adicionando cep no formulário base de inscrição e adicionando o formulário que gera...
[cascardo/eventmanager.git] / forms.py
1 # -*- coding: utf-8; -*-
2 """
3 Copyright (C) 2007 Lincoln de Sousa <lincoln@archlinux-br.org>
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public
16 License along with this program; if not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 """
20 from django import newforms as forms
21 from django.newforms import ValidationError
22 from django.newforms.widgets import Textarea, PasswordInput, HiddenInput
23 from django.contrib.auth.models import User
24 from eventmanager.eventos.models import \
25         TipoTrabalho, CategoriaTrabalho, Palestrante, STATE_CHOICES
26
27 MKCHOICES = lambda K, xid=-1:[(x.id, str(x)) for x in K.objects.all() \
28         if xid != x.id]
29
30 class LoginBase(forms.Form):
31     nome_usuario = forms.CharField(max_length=100)
32     senha = forms.CharField(max_length=100, widget=PasswordInput())
33     senha_2 = forms.CharField(max_length=100, widget=PasswordInput(),
34         label='Conferir Senha')
35
36     def clean_nome_usuario(self):
37         try:
38             User.objects.get(username=self.cleaned_data['nome_usuario'])
39             raise ValidationError('Já existe um usuário com esse nome')
40         except User.DoesNotExist:
41             return self.cleaned_data['nome_usuario']
42
43     def clean_senha_2(self):
44         if self.cleaned_data['senha'] != self.cleaned_data['senha_2']:
45             raise ValidationError('A confirmação não confere com a senha')
46         return self.cleaned_data['senha_2']
47
48 class SubmeterTrabalho(forms.Form):
49     def __init__(self, request, *args, **kwargs):
50         super(SubmeterTrabalho, self).__init__(*args, **kwargs)
51
52         newchoices = MKCHOICES(TipoTrabalho)
53         self.fields['tipo'].choices = newchoices
54
55         palestrante = request.user.palestrante_set.get()
56         newchoices = MKCHOICES(Palestrante, xid=palestrante.id)
57         self.fields['outros_palestrantes'].choices = newchoices
58
59     titulo = forms.CharField(max_length=100, label='Título do trabalho')
60     tipo = forms.ChoiceField()
61     descricao_curta = forms.CharField(widget=Textarea(),
62         label='Descrição curta', max_length=250,
63         help_text='Esta descrição será utilizada para exibição no '
64                   'material de divulgação (máximo 250 caracteres).')
65     descricao_longa = forms.CharField(widget=Textarea(),
66         max_length=1500, label='Descrição longa',
67         help_text='Esta descrição será utilizada para avaliação do seu '
68                   'trabalho. Insira também referências '
69                   '(máximo 1500 caracteres).')
70     recursos = forms.CharField(widget=Textarea(), max_length=300, required=0,
71         help_text='Liste os recursos que seu trabalho irá necessitar, '
72                   'ex.: Computadores, softwares, etc. Máximo de 300 caracteres.')
73     outros_palestrantes = forms.MultipleChoiceField(required=0)
74
75 class CadastroPalestrante(LoginBase):
76     nome_completo = forms.CharField(max_length=100)
77     email = forms.CharField(max_length=100)
78
79     telefone = forms.CharField(required=False)
80     celular = forms.CharField(required=False)
81
82     instituicao = forms.CharField(max_length=100, label='Instituição')
83     minicurriculo = forms.CharField(widget=Textarea(), max_length=250, label='Mini Currículo',
84        help_text='Este mini currículo será utilizado no material de divulgação '
85                  'e no sítio. Máximo de 250 caracteres.')
86     curriculo = forms.CharField(widget=Textarea(), max_length=6000, label='Currículo',
87        help_text='Este currículo será utilizado para avaliação do palestrante. '
88                  'Máximo de 6000 caracteres.')
89     rua = forms.CharField(max_length=100)
90     numero = forms.CharField(max_length=10, label='Número')
91     bairro = forms.CharField(max_length=100)
92     cidade = forms.CharField(max_length=100)
93     uf = forms.ChoiceField(choices=STATE_CHOICES)
94
95     def clean_celular(self):
96         if not self.cleaned_data['telefone'] and \
97            not self.cleaned_data['celular']:
98             raise ValidationError('Algum número de precisa ser preenchido')
99         return self.cleaned_data['celular']
100
101 class EditarPalestrante(forms.Form):
102     nome = forms.CharField(max_length=100, label='Nome completo')
103     email = forms.CharField(max_length=100)
104
105     telefone = forms.CharField(required=False)
106     celular = forms.CharField(required=False)
107
108     instituicao = forms.CharField(max_length=100, label='Instituição')
109     minicurriculo = forms.CharField(widget=Textarea(), max_length=250, label='Mini Currículo',
110        help_text='Este mini currículo será utilizado no material de divulgação'
111                  'e no site. Máximo de 250 caracteres.')
112     curriculo = forms.CharField(widget=Textarea(), max_length=6000, label='Currículo',
113        help_text='Este currículo será utilizado para avaliação do palestrante.'
114                  'Máximo de 6000 caracteres.')
115     rua = forms.CharField(max_length=100)
116     numero = forms.CharField(max_length=10, label='Número')
117     bairro = forms.CharField(max_length=100)
118     cidade = forms.CharField(max_length=100)
119     uf = forms.ChoiceField(choices=STATE_CHOICES)
120
121 class EditarSenha(forms.Form):
122     senha_atual = forms.CharField(max_length=100, widget=PasswordInput())
123     nova_senha = forms.CharField(max_length=100, widget=PasswordInput())
124     nova_senha_2 = forms.CharField(max_length=100, widget=PasswordInput(),
125         label='Conferir Senha')
126
127 class InscricaoBase(LoginBase):
128     nome_completo = forms.CharField(max_length=100)
129     rg = forms.CharField(max_length=100)
130
131     email = forms.CharField(max_length=100)
132     rua = forms.CharField(max_length=100)
133     numero = forms.CharField(max_length=10, label='Número')
134     bairro = forms.CharField(max_length=100)
135     cidade = forms.CharField(max_length=100)
136     uf = forms.ChoiceField(choices=STATE_CHOICES)
137     cep = forms.CharField(max_length=8, help_text='Somente números')
138     telefone = forms.CharField(max_length=100)
139     home_page = forms.CharField(max_length=100, label='Página Pessoal',
140         required=False)
141
142 class Inscricao(InscricaoBase):
143     inscricao_comercial = forms.BooleanField(required=False,
144         label='Inscrição Comercial')
145
146 class InscricaoCaravana(InscricaoBase):
147     lista_nomes = forms.CharField(label='Lista de nomes',
148         widget=forms.Textarea(), help_text='Um participante por linha, '
149         'informando nome completo e email no seguine formato: '
150         'Nome Completo &lt;email@server.domain&gt;')
151
152     def clean_lista_nomes(self):
153         nomes = self.cleaned_data['lista_nomes']
154         if len([x for x in nomes.split('\n') if x]) < 10:
155             raise ValidationError('A caravana precisa de pelo menos 10 '
156                     'participantes.')
157         return nomes
158
159 class Boleto(forms.Form):
160     # Field names are in mixedCase because of bb's sistem request =/
161     idConv = forms.CharField(max_length=6, initial='303366',
162             widget=HiddenInput())
163     refTran = forms.CharField(max_length=17, initial='14581970000000002',
164             widget=HiddenInput())
165     tpPagamento = forms.CharField(max_length=2, initial='21',
166             widget=HiddenInput())
167     valor = forms.CharField(max_length=15, widget=HiddenInput())
168     dtVenc = forms.CharField(max_length=8, widget=HiddenInput())
169     urlRetorno = forms.CharField(max_length=60, initial='/inscricao',
170             widget=HiddenInput())
171     urlInforma = forms.CharField(max_length=60, initial='/inscricao',
172             widget=HiddenInput())
173     nome = forms.CharField(max_length=60, widget=HiddenInput())
174     endereco = forms.CharField(max_length=60, widget=HiddenInput())
175     cidade = forms.CharField(max_length=18, widget=HiddenInput())
176     uf = forms.CharField(max_length=2, widget=HiddenInput())
177     cep = forms.CharField(max_length=8, widget=HiddenInput())
178     msgLoja = forms.CharField(max_length=480,
179             initial='Nao receber apos a data de vencimento',
180             widget=HiddenInput())