colocando um layout tosco...
[cascardo/ema.git] / eventos / forms.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2008 Lincoln de Sousa <lincoln@minaslivre.org>
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 2 of the
7 # License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public
15 # License along with this program; if not, write to the
16 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 # Boston, MA 02111-1307, USA.
18 from django import newforms as forms
19 from django.newforms import PasswordInput, ValidationError
20 from django.contrib.auth.models import User
21
22
23 class RegisterLecturer(forms.Form):
24     username = forms.CharField(max_length=20, label=u'Usuário para login')
25     password1 = forms.CharField(widget=PasswordInput, label='Senha')
26     password2 = forms.CharField(widget=PasswordInput, label='Confirmar Senha')
27
28     def clean_password2(self):
29         if self.cleaned_data['password1'] != self.cleaned_data['password2']:
30             raise ValidationError('A confirmação não confere com a senha')
31         return self.cleaned_data['password2']
32
33     def clean_username(self):
34         try:
35             User.objects.get(username=self.cleaned_data['username'])
36             raise ValidationError('Já existe um usuário com esse nome')
37         except User.DoesNotExist:
38             return self.cleaned_data['username']