Commit 9f9b14570d6184d8ee7953b679d058a89c64a895
1 parent
22b91751
Exists in
master
and in
39 other branches
Fixed form css for users
Showing
3 changed files
with
31 additions
and
48 deletions
Show diff stats
colab/accounts/admin.py
| @@ -31,7 +31,8 @@ class CustomUserAdmin(UserAdmin): | @@ -31,7 +31,8 @@ class CustomUserAdmin(UserAdmin): | ||
| 31 | add_fieldsets = ( | 31 | add_fieldsets = ( |
| 32 | (None, { | 32 | (None, { |
| 33 | 'classes': ('wide',), | 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,13 +36,13 @@ class SocialAccountField(forms.Field): | ||
| 36 | 36 | ||
| 37 | class UserForm(forms.ModelForm): | 37 | class UserForm(forms.ModelForm): |
| 38 | username = forms.CharField( | 38 | username = forms.CharField( |
| 39 | - | ||
| 40 | # Forces username to be lowercase always | 39 | # Forces username to be lowercase always |
| 41 | widget=forms.TextInput(attrs={'style': 'text-transform: lowercase;'}), | 40 | widget=forms.TextInput(attrs={'style': 'text-transform: lowercase;'}), |
| 42 | ) | 41 | ) |
| 43 | required = ('first_name', 'last_name', 'username') | 42 | required = ('first_name', 'last_name', 'username') |
| 44 | 43 | ||
| 45 | class Meta: | 44 | class Meta: |
| 45 | + fields = ('first_name', 'last_name', 'username') | ||
| 46 | model = User | 46 | model = User |
| 47 | 47 | ||
| 48 | def __init__(self, *args, **kwargs): | 48 | def __init__(self, *args, **kwargs): |
| @@ -55,6 +55,12 @@ class UserForm(forms.ModelForm): | @@ -55,6 +55,12 @@ class UserForm(forms.ModelForm): | ||
| 55 | if field_name in UserForm.required: | 55 | if field_name in UserForm.required: |
| 56 | field.required = True | 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 | class UserUpdateForm(UserForm): | 65 | class UserUpdateForm(UserForm): |
| 60 | bio = forms.CharField( | 66 | bio = forms.CharField( |
| @@ -127,7 +133,7 @@ class ChangeXMPPPasswordForm(forms.ModelForm): | @@ -127,7 +133,7 @@ class ChangeXMPPPasswordForm(forms.ModelForm): | ||
| 127 | return self.instance | 133 | return self.instance |
| 128 | 134 | ||
| 129 | 135 | ||
| 130 | -class UserCreationForm(forms.ModelForm): | 136 | +class UserCreationForm(UserForm): |
| 131 | """ | 137 | """ |
| 132 | A form that creates a user, with no privileges, from the given username and | 138 | A form that creates a user, with no privileges, from the given username and |
| 133 | password. | 139 | password. |
| @@ -151,11 +157,14 @@ class UserCreationForm(forms.ModelForm): | @@ -151,11 +157,14 @@ class UserCreationForm(forms.ModelForm): | ||
| 151 | widget=forms.PasswordInput, | 157 | widget=forms.PasswordInput, |
| 152 | help_text=_(("Enter the same password as above" | 158 | help_text=_(("Enter the same password as above" |
| 153 | ", for verification."))) | 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 | class Meta: | 165 | class Meta: |
| 157 | model = User | 166 | model = User |
| 158 | - fields = ("username",) | 167 | + fields = ("username", "first_name", "last_name", "email") |
| 159 | 168 | ||
| 160 | def clean_username(self): | 169 | def clean_username(self): |
| 161 | # Since User.username is unique, this check is redundant, | 170 | # Since User.username is unique, this check is redundant, |
| @@ -227,37 +236,6 @@ class UserChangeForm(forms.ModelForm): | @@ -227,37 +236,6 @@ class UserChangeForm(forms.ModelForm): | ||
| 227 | return self.initial["password"] | 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 | class AuthenticationForm(forms.Form): | 239 | class AuthenticationForm(forms.Form): |
| 262 | """ | 240 | """ |
| 263 | Base class for authenticating users. Extend this to get a form that accepts | 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,11 +20,12 @@ from conversejs import xmpp | ||
| 20 | from conversejs.models import XMPPAccount | 20 | from conversejs.models import XMPPAccount |
| 21 | from haystack.query import SearchQuerySet | 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 | from colab.search.utils import trans | 25 | from colab.search.utils import trans |
| 25 | # from proxy.trac.models import WikiCollabCount, TicketCollabCount | 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 | # from .errors import XMPPChangePwdException | 29 | # from .errors import XMPPChangePwdException |
| 29 | from .utils import mailman | 30 | from .utils import mailman |
| 30 | 31 | ||
| @@ -147,18 +148,18 @@ def signup(request): | @@ -147,18 +148,18 @@ def signup(request): | ||
| 147 | # will be redirected to the register form. | 148 | # will be redirected to the register form. |
| 148 | if request.method == 'GET': | 149 | if request.method == 'GET': |
| 149 | if BROWSERID_ENABLED: | 150 | if BROWSERID_ENABLED: |
| 150 | - user_form = UserCreationForm() | 151 | + user_form = UserForm() |
| 151 | else: | 152 | else: |
| 152 | - user_form = UserCreationFormNoBrowserId() | 153 | + user_form = UserCreationForm() |
| 153 | lists_form = ListsForm() | 154 | lists_form = ListsForm() |
| 154 | 155 | ||
| 155 | return render(request, 'accounts/user_create_form.html', | 156 | return render(request, 'accounts/user_create_form.html', |
| 156 | {'user_form': user_form, 'lists_form': lists_form}) | 157 | {'user_form': user_form, 'lists_form': lists_form}) |
| 157 | 158 | ||
| 158 | if BROWSERID_ENABLED: | 159 | if BROWSERID_ENABLED: |
| 159 | - user_form = UserCreationForm(request.POST, instance=request.user) | 160 | + user_form = UserForm(request.POST, instance=request.user) |
| 160 | else: | 161 | else: |
| 161 | - user_form = UserCreationFormNoBrowserId(request.POST) | 162 | + user_form = UserCreationForm(request.POST) |
| 162 | lists_form = ListsForm(request.POST) | 163 | lists_form = ListsForm(request.POST) |
| 163 | 164 | ||
| 164 | if not user_form.is_valid() or not lists_form.is_valid(): | 165 | if not user_form.is_valid() or not lists_form.is_valid(): |
| @@ -190,7 +191,6 @@ def signup(request): | @@ -190,7 +191,6 @@ def signup(request): | ||
| 190 | 191 | ||
| 191 | messages.success(request, _('Your profile has been created!')) | 192 | messages.success(request, _('Your profile has been created!')) |
| 192 | 193 | ||
| 193 | - | ||
| 194 | return redirect('user_profile', username=user.username) | 194 | return redirect('user_profile', username=user.username) |
| 195 | 195 | ||
| 196 | 196 | ||
| @@ -286,6 +286,7 @@ class ChangeXMPPPasswordView(UpdateView): | @@ -286,6 +286,7 @@ class ChangeXMPPPasswordView(UpdateView): | ||
| 286 | ) | 286 | ) |
| 287 | return response | 287 | return response |
| 288 | 288 | ||
| 289 | + | ||
| 289 | def password_changed(request): | 290 | def password_changed(request): |
| 290 | messages.success(request, _('Your password was changed.')) | 291 | messages.success(request, _('Your password was changed.')) |
| 291 | 292 | ||
| @@ -293,14 +294,17 @@ def password_changed(request): | @@ -293,14 +294,17 @@ def password_changed(request): | ||
| 293 | 294 | ||
| 294 | return redirect('user_profile_update', username=user.username) | 295 | return redirect('user_profile_update', username=user.username) |
| 295 | 296 | ||
| 297 | + | ||
| 296 | def password_reset_done_custom(request): | 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 | return redirect('home') | 303 | return redirect('home') |
| 300 | 304 | ||
| 305 | + | ||
| 301 | def password_reset_complete_custom(request): | 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 | return redirect('home') | 310 | return redirect('home') |
| 305 | - | ||
| 306 | - |