Commit 9f9b14570d6184d8ee7953b679d058a89c64a895

Authored by Sergio Oliveira
1 parent 22b91751

Fixed form css for users

colab/accounts/admin.py
... ... @@ -31,7 +31,8 @@ class CustomUserAdmin(UserAdmin):
31 31 add_fieldsets = (
32 32 (None, {
33 33 'classes': ('wide',),
34   - 'fields': ('username', 'email', 'password1', 'password2'),
  34 + 'fields': ('username', 'first_name', 'last_name',
  35 + 'email', 'password1', 'password2'),
35 36 }),
36 37 )
37 38  
... ...
colab/accounts/forms.py
... ... @@ -36,13 +36,13 @@ class SocialAccountField(forms.Field):
36 36  
37 37 class UserForm(forms.ModelForm):
38 38 username = forms.CharField(
39   -
40 39 # Forces username to be lowercase always
41 40 widget=forms.TextInput(attrs={'style': 'text-transform: lowercase;'}),
42 41 )
43 42 required = ('first_name', 'last_name', 'username')
44 43  
45 44 class Meta:
  45 + fields = ('first_name', 'last_name', 'username')
46 46 model = User
47 47  
48 48 def __init__(self, *args, **kwargs):
... ... @@ -55,6 +55,12 @@ class UserForm(forms.ModelForm):
55 55 if field_name in UserForm.required:
56 56 field.required = True
57 57  
  58 + def clean_username(self):
  59 + username = self.cleaned_data["username"].strip()
  60 + if not username:
  61 + raise forms.ValidationError(_('This field cannot be blank.'))
  62 + return username
  63 +
58 64  
59 65 class UserUpdateForm(UserForm):
60 66 bio = forms.CharField(
... ... @@ -127,7 +133,7 @@ class ChangeXMPPPasswordForm(forms.ModelForm):
127 133 return self.instance
128 134  
129 135  
130   -class UserCreationForm(forms.ModelForm):
  136 +class UserCreationForm(UserForm):
131 137 """
132 138 A form that creates a user, with no privileges, from the given username and
133 139 password.
... ... @@ -151,11 +157,14 @@ class UserCreationForm(forms.ModelForm):
151 157 widget=forms.PasswordInput,
152 158 help_text=_(("Enter the same password as above"
153 159 ", for verification.")))
154   - email = forms.EmailField(required=True)
  160 +
  161 + def __init__(self, *args, **kwargs):
  162 + super(UserCreationForm, self).__init__(*args, **kwargs)
  163 + self.fields['email'].required = True
155 164  
156 165 class Meta:
157 166 model = User
158   - fields = ("username",)
  167 + fields = ("username", "first_name", "last_name", "email")
159 168  
160 169 def clean_username(self):
161 170 # Since User.username is unique, this check is redundant,
... ... @@ -227,37 +236,6 @@ class UserChangeForm(forms.ModelForm):
227 236 return self.initial["password"]
228 237  
229 238  
230   -class UserCreationFormNoBrowserId(UserCreationForm):
231   -
232   - password1 = forms.CharField(label=_("Password"),
233   - widget=forms.PasswordInput)
234   - password2 = forms.CharField(label=_("Confirm Password "),
235   - widget=forms.PasswordInput)
236   - email = forms.EmailField(label=_("Email address"), required=True)
237   -
238   - class Meta:
239   - model = User
240   - fields = ('first_name', 'last_name', 'email', 'username')
241   -
242   - def clean_password2(self):
243   - password1 = self.cleaned_data.get('password1')
244   - password2 = self.cleaned_data.get('password2')
245   -
246   - if password1 and password2 and password1 != password2:
247   - raise forms.ValidationError(
248   - _("The two password fields didn't match."))
249   - return password2
250   -
251   - def save(self, commit=True):
252   - """
253   - Saves the new password.
254   - """
255   - self.instance.set_password(self.cleaned_data["password1"])
256   - if commit:
257   - self.instance.save()
258   - return self.instance
259   -
260   -
261 239 class AuthenticationForm(forms.Form):
262 240 """
263 241 Base class for authenticating users. Extend this to get a form that accepts
... ...
colab/accounts/views.py
... ... @@ -20,11 +20,12 @@ from conversejs import xmpp
20 20 from conversejs.models import XMPPAccount
21 21 from haystack.query import SearchQuerySet
22 22  
23   -from colab.super_archives.models import EmailAddress, Message, EmailAddressValidation
  23 +from colab.super_archives.models import (EmailAddress, Message,
  24 + EmailAddressValidation)
24 25 from colab.search.utils import trans
25 26 # from proxy.trac.models import WikiCollabCount, TicketCollabCount
26   -from .forms import (UserCreationForm, UserCreationFormNoBrowserId, ListsForm, UserUpdateForm,
27   - ChangeXMPPPasswordForm)
  27 +from .forms import (UserCreationForm, UserForm, ListsForm,
  28 + UserUpdateForm, ChangeXMPPPasswordForm)
28 29 # from .errors import XMPPChangePwdException
29 30 from .utils import mailman
30 31  
... ... @@ -147,18 +148,18 @@ def signup(request):
147 148 # will be redirected to the register form.
148 149 if request.method == 'GET':
149 150 if BROWSERID_ENABLED:
150   - user_form = UserCreationForm()
  151 + user_form = UserForm()
151 152 else:
152   - user_form = UserCreationFormNoBrowserId()
  153 + user_form = UserCreationForm()
153 154 lists_form = ListsForm()
154 155  
155 156 return render(request, 'accounts/user_create_form.html',
156 157 {'user_form': user_form, 'lists_form': lists_form})
157 158  
158 159 if BROWSERID_ENABLED:
159   - user_form = UserCreationForm(request.POST, instance=request.user)
  160 + user_form = UserForm(request.POST, instance=request.user)
160 161 else:
161   - user_form = UserCreationFormNoBrowserId(request.POST)
  162 + user_form = UserCreationForm(request.POST)
162 163 lists_form = ListsForm(request.POST)
163 164  
164 165 if not user_form.is_valid() or not lists_form.is_valid():
... ... @@ -190,7 +191,6 @@ def signup(request):
190 191  
191 192 messages.success(request, _('Your profile has been created!'))
192 193  
193   -
194 194 return redirect('user_profile', username=user.username)
195 195  
196 196  
... ... @@ -286,6 +286,7 @@ class ChangeXMPPPasswordView(UpdateView):
286 286 )
287 287 return response
288 288  
  289 +
289 290 def password_changed(request):
290 291 messages.success(request, _('Your password was changed.'))
291 292  
... ... @@ -293,14 +294,17 @@ def password_changed(request):
293 294  
294 295 return redirect('user_profile_update', username=user.username)
295 296  
  297 +
296 298 def password_reset_done_custom(request):
297   - messages.success(request, _('We\'ve emailed you instructions for setting your password. You should be receiving them shortly.'))
  299 + msg = _(("We've emailed you instructions for setting "
  300 + "your password. You should be receiving them shortly."))
  301 + messages.success(request, msg)
298 302  
299 303 return redirect('home')
300 304  
  305 +
301 306 def password_reset_complete_custom(request):
302   - messages.success(request, _('Your password has been set. You may go ahead and log in now.'))
  307 + msg = _('Your password has been set. You may go ahead and log in now.')
  308 + messages.success(request, msg)
303 309  
304 310 return redirect('home')
305   -
306   -
... ...