def clean(self): """ Do validation """ super(EmployeeForm, self).clean() username = self.cleaned_data.get('first_name') if username: if not Employee.isValidUsername(username): raise forms.ValidationError( _('Invalid username format. Accepted characters are A-Z,a-z,0-9,_-,.' )) if get_user_model().objects.filter( username__exact=username).exists(): raise forms.ValidationError( _('A user with the given username already exists')) email = self.cleaned_data.get('email') # confirm_email = self.cleaned_data.get('confirm_email') # if not email == confirm_email: # raise forms.ValidationError(_('The emails are not equal')) if UserNxtlvl.objects.filter( email__exact=self.cleaned_data.get('email')).exists(): raise forms.ValidationError( _('A user with the given email already exists')) return self.cleaned_data
def clean(self): """ Do validation """ super(EmployeeForm, self).clean() username = self.cleaned_data.get('user_name') if username: if not Employee.isValidUsername(username): raise forms.ValidationError(_( 'Invalid username format. Accepted characters are A-Z,a-z,0-9,_-,.' )) if User.objects.filter(username__exact = username).exists(): raise forms.ValidationError(_('A user with the given username already exists')) email = self.cleaned_data.get('email') confirm_email = self.cleaned_data.get('confirm_email') if not email == confirm_email: raise forms.ValidationError(_('The emails are not equal')) if User.objects.filter(email__exact = self.cleaned_data.get('email')).exists(): raise forms.ValidationError(_('A user with the given email already exists')) return self.cleaned_data
def clean(self): if any(self.errors): return username = self.cleaned_data['username'].strip() if username: if not Employee.isValidUsername(username): raise forms.ValidationError(_( 'Invalid username format. Accepted characters are A-Z,a-z,0-9,_-,.' )) if User.objects.filter(username__exact = username).exists(): raise forms.ValidationError(_('A user with the given username already exists')) return self.cleaned_data
def clean(self): if any(self.errors): return username = self.cleaned_data['username'].strip() if username: if not Employee.isValidUsername(username): raise forms.ValidationError( _('Invalid username format. Accepted characters are A-Z,a-z,0-9,_-,.' )) if get_user_model().objects.filter( username__exact=username).exists(): raise forms.ValidationError( _('A user with the given username already exists')) return self.cleaned_data