From aef211b9ad52f33f55cbb6199fdd2cf85db2672d Mon Sep 17 00:00:00 2001 From: Carlos Oliveira Date: Wed, 17 Dec 2014 16:33:04 -0200 Subject: [PATCH] Validated blank space in username field --- colab/accounts/forms.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/colab/accounts/forms.py b/colab/accounts/forms.py index 0b65436..c0d10b3 100644 --- a/colab/accounts/forms.py +++ b/colab/accounts/forms.py @@ -32,11 +32,6 @@ class UserForm(forms.ModelForm): # Forces username to be lowercase always widget=forms.TextInput(attrs={'style' : 'text-transform: lowercase;'}), ) - email = forms.EmailField( - - # Forces email to be a read-only field - widget=forms.TextInput(attrs={'readonly': 'readonly'}) - ) required = ('first_name', 'last_name', 'email', 'username') class Meta: @@ -53,8 +48,20 @@ class UserForm(forms.ModelForm): field.required = True - class UserCreationForm(UserForm): + email = forms.EmailField( + + # Forces email to be a read-only field + widget=forms.TextInput(attrs={'readonly': 'readonly'}) + ) + + def clean_username(self): + username = self.cleaned_data['username'] + username = username.strip() + if len(username) is 0: + raise forms.ValidationError('This field should not be blank.') + return username + class Meta: model = User fields = ('first_name', 'last_name', 'email', 'username') -- libgit2 0.21.2