From 9f9b14570d6184d8ee7953b679d058a89c64a895 Mon Sep 17 00:00:00 2001 From: Sergio Oliveira Date: Fri, 23 Jan 2015 16:54:43 -0200 Subject: [PATCH] Fixed form css for users --- colab/accounts/admin.py | 3 ++- colab/accounts/forms.py | 48 +++++++++++++----------------------------------- colab/accounts/views.py | 28 ++++++++++++++++------------ 3 files changed, 31 insertions(+), 48 deletions(-) diff --git a/colab/accounts/admin.py b/colab/accounts/admin.py index c183c4c..799042b 100644 --- a/colab/accounts/admin.py +++ b/colab/accounts/admin.py @@ -31,7 +31,8 @@ class CustomUserAdmin(UserAdmin): add_fieldsets = ( (None, { 'classes': ('wide',), - 'fields': ('username', 'email', 'password1', 'password2'), + 'fields': ('username', 'first_name', 'last_name', + 'email', 'password1', 'password2'), }), ) diff --git a/colab/accounts/forms.py b/colab/accounts/forms.py index 5a1456f..c80f974 100644 --- a/colab/accounts/forms.py +++ b/colab/accounts/forms.py @@ -36,13 +36,13 @@ class SocialAccountField(forms.Field): class UserForm(forms.ModelForm): username = forms.CharField( - # Forces username to be lowercase always widget=forms.TextInput(attrs={'style': 'text-transform: lowercase;'}), ) required = ('first_name', 'last_name', 'username') class Meta: + fields = ('first_name', 'last_name', 'username') model = User def __init__(self, *args, **kwargs): @@ -55,6 +55,12 @@ class UserForm(forms.ModelForm): if field_name in UserForm.required: field.required = True + def clean_username(self): + username = self.cleaned_data["username"].strip() + if not username: + raise forms.ValidationError(_('This field cannot be blank.')) + return username + class UserUpdateForm(UserForm): bio = forms.CharField( @@ -127,7 +133,7 @@ class ChangeXMPPPasswordForm(forms.ModelForm): return self.instance -class UserCreationForm(forms.ModelForm): +class UserCreationForm(UserForm): """ A form that creates a user, with no privileges, from the given username and password. @@ -151,11 +157,14 @@ class UserCreationForm(forms.ModelForm): widget=forms.PasswordInput, help_text=_(("Enter the same password as above" ", for verification."))) - email = forms.EmailField(required=True) + + def __init__(self, *args, **kwargs): + super(UserCreationForm, self).__init__(*args, **kwargs) + self.fields['email'].required = True class Meta: model = User - fields = ("username",) + fields = ("username", "first_name", "last_name", "email") def clean_username(self): # Since User.username is unique, this check is redundant, @@ -227,37 +236,6 @@ class UserChangeForm(forms.ModelForm): return self.initial["password"] -class UserCreationFormNoBrowserId(UserCreationForm): - - password1 = forms.CharField(label=_("Password"), - widget=forms.PasswordInput) - password2 = forms.CharField(label=_("Confirm Password "), - widget=forms.PasswordInput) - email = forms.EmailField(label=_("Email address"), required=True) - - class Meta: - model = User - fields = ('first_name', 'last_name', 'email', 'username') - - def clean_password2(self): - password1 = self.cleaned_data.get('password1') - password2 = self.cleaned_data.get('password2') - - if password1 and password2 and password1 != password2: - raise forms.ValidationError( - _("The two password fields didn't match.")) - return password2 - - def save(self, commit=True): - """ - Saves the new password. - """ - self.instance.set_password(self.cleaned_data["password1"]) - if commit: - self.instance.save() - return self.instance - - class AuthenticationForm(forms.Form): """ Base class for authenticating users. Extend this to get a form that accepts diff --git a/colab/accounts/views.py b/colab/accounts/views.py index d82add4..f2f9187 100644 --- a/colab/accounts/views.py +++ b/colab/accounts/views.py @@ -20,11 +20,12 @@ from conversejs import xmpp from conversejs.models import XMPPAccount from haystack.query import SearchQuerySet -from colab.super_archives.models import EmailAddress, Message, EmailAddressValidation +from colab.super_archives.models import (EmailAddress, Message, + EmailAddressValidation) from colab.search.utils import trans # from proxy.trac.models import WikiCollabCount, TicketCollabCount -from .forms import (UserCreationForm, UserCreationFormNoBrowserId, ListsForm, UserUpdateForm, - ChangeXMPPPasswordForm) +from .forms import (UserCreationForm, UserForm, ListsForm, + UserUpdateForm, ChangeXMPPPasswordForm) # from .errors import XMPPChangePwdException from .utils import mailman @@ -147,18 +148,18 @@ def signup(request): # will be redirected to the register form. if request.method == 'GET': if BROWSERID_ENABLED: - user_form = UserCreationForm() + user_form = UserForm() else: - user_form = UserCreationFormNoBrowserId() + user_form = UserCreationForm() lists_form = ListsForm() return render(request, 'accounts/user_create_form.html', {'user_form': user_form, 'lists_form': lists_form}) if BROWSERID_ENABLED: - user_form = UserCreationForm(request.POST, instance=request.user) + user_form = UserForm(request.POST, instance=request.user) else: - user_form = UserCreationFormNoBrowserId(request.POST) + user_form = UserCreationForm(request.POST) lists_form = ListsForm(request.POST) if not user_form.is_valid() or not lists_form.is_valid(): @@ -190,7 +191,6 @@ def signup(request): messages.success(request, _('Your profile has been created!')) - return redirect('user_profile', username=user.username) @@ -286,6 +286,7 @@ class ChangeXMPPPasswordView(UpdateView): ) return response + def password_changed(request): messages.success(request, _('Your password was changed.')) @@ -293,14 +294,17 @@ def password_changed(request): return redirect('user_profile_update', username=user.username) + def password_reset_done_custom(request): - messages.success(request, _('We\'ve emailed you instructions for setting your password. You should be receiving them shortly.')) + msg = _(("We've emailed you instructions for setting " + "your password. You should be receiving them shortly.")) + messages.success(request, msg) return redirect('home') + def password_reset_complete_custom(request): - messages.success(request, _('Your password has been set. You may go ahead and log in now.')) + msg = _('Your password has been set. You may go ahead and log in now.') + messages.success(request, msg) return redirect('home') - - -- libgit2 0.21.2