X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fema.git;a=blobdiff_plain;f=eventos%2Fforms.py;fp=eventos%2Fforms.py;h=3c8acea67c93871b559b35424869e1b556fbccfb;hp=8e3980e87880358bd397405f9cacc0398863ac22;hb=71d5020d87c6ffbdf4b30ab07937623563b45c6d;hpb=dba30d749f678328c1aded3e7d2813bf27646152 diff --git a/eventos/forms.py b/eventos/forms.py index 8e3980e..3c8acea 100644 --- a/eventos/forms.py +++ b/eventos/forms.py @@ -15,3 +15,24 @@ # License along with this program; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. +from django import newforms as forms +from django.newforms import PasswordInput, ValidationError +from django.contrib.auth.models import User + + +class RegisterLecturer(forms.Form): + username = forms.CharField(max_length=20, label=u'Usuário para login') + password1 = forms.CharField(widget=PasswordInput, label='Senha') + password2 = forms.CharField(widget=PasswordInput, label='Confirmar Senha') + + def clean_password2(self): + if self.cleaned_data['password1'] != self.cleaned_data['password2']: + raise ValidationError('A confirmação não confere com a senha') + return self.cleaned_data['password2'] + + def clean_username(self): + try: + User.objects.get(username=self.cleaned_data['username']) + raise ValidationError('Já existe um usuário com esse nome') + except User.DoesNotExist: + return self.cleaned_data['username']