from django import forms from django.contrib.auth.models import User from django.utils.translation import ugettext_lazy as _ from seaserv import ccnet_rpc, ccnet_threaded_rpc class AddUserForm(forms.Form): """ Form for adding a user. """ email = forms.EmailField() password1 = forms.CharField(widget=forms.PasswordInput()) password2 = forms.CharField(widget=forms.PasswordInput()) def clean_email(self): email = self.cleaned_data['email'] emailuser = ccnet_threaded_rpc.get_emailuser(email) if not emailuser: return self.cleaned_data['email'] else: raise forms.ValidationError(_("A user with this email already")) def clean(self): """ Verifiy that the values entered into the two password fields match. Note that an error here will end up in ``non_field_errors()`` because it doesn't apply to a single field. """ if 'password1' in self.cleaned_data and 'password2' in self.cleaned_data: if self.cleaned_data['password1'] != self.cleaned_data['password2']: raise forms.ValidationError(_("The two password fields didn't match.")) return self.cleaned_data