1 # -*- coding: utf-8; -*-
3 Copyright (C) 2007 Lincoln de Sousa <lincoln@archlinux-br.org>
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.
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.
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.
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
27 MKCHOICES = lambda K, xid=-1:[(x.id, str(x)) for x in K.objects.all() \
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')
36 def clean_nome_usuario(self):
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']
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']
48 class SubmeterTrabalho(forms.Form):
49 def __init__(self, request, *args, **kwargs):
50 super(SubmeterTrabalho, self).__init__(*args, **kwargs)
52 newchoices = MKCHOICES(TipoTrabalho)
53 self.fields['tipo'].choices = newchoices
55 palestrante = request.user.palestrante_set.get()
56 newchoices = MKCHOICES(Palestrante, xid=palestrante.id)
57 self.fields['outros_palestrantes'].choices = newchoices
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)
75 class CadastroPalestrante(LoginBase):
76 nome_completo = forms.CharField(max_length=100)
77 email = forms.CharField(max_length=100)
79 telefone = forms.CharField(required=False)
80 celular = forms.CharField(required=False)
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)
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']
101 class EditarPalestrante(forms.Form):
102 nome = forms.CharField(max_length=100, label='Nome completo')
103 email = forms.CharField(max_length=100)
105 telefone = forms.CharField(required=False)
106 celular = forms.CharField(required=False)
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)
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')
127 class InscricaoBase(LoginBase):
128 nome_completo = forms.CharField(max_length=100)
129 rg = forms.CharField(max_length=100)
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',
142 class Inscricao(InscricaoBase):
143 inscricao_comercial = forms.BooleanField(required=False,
144 label='Inscrição Comercial')
145 cpf_cnpj = forms.CharField(max_length=20, required=False, label='CPF/CNPJ',
146 help_text='Somente necessário para a inscrição comercial')
148 def clean_cpf_cnpj(self):
149 cpf_cnpj = self.cleaned_data['cpf_cnpj']
150 if self.cleaned_data['inscricao_comercial'] and not cpf_cnpj:
151 raise ValidationError('Você escolheu a inscrição comercial, '
152 'portanto este campo se torna obrigatório')
155 class InscricaoCaravana(InscricaoBase):
156 lista_nomes = forms.CharField(label='Lista de nomes',
157 widget=forms.Textarea(), help_text='Um participante por linha, '
158 'informando nome completo e email no seguine formato: '
159 'Nome Completo <email@server.domain>')
161 def clean_lista_nomes(self):
162 nomes = self.cleaned_data['lista_nomes']
163 if len([x for x in nomes.split('\n') if x]) < 10:
164 raise ValidationError('A caravana precisa de pelo menos 10 '
168 class Boleto(forms.Form):
169 # Field names are in mixedCase because of bb's sistem request =/
170 idConv = forms.CharField(max_length=6, initial='303366',
171 widget=HiddenInput())
172 refTran = forms.CharField(max_length=17,
173 widget=HiddenInput())
174 tpPagamento = forms.CharField(max_length=2, initial='21',
175 widget=HiddenInput())
176 valor = forms.CharField(max_length=15, widget=HiddenInput())
177 dtVenc = forms.CharField(max_length=8, widget=HiddenInput())
178 urlRetorno = forms.CharField(max_length=60, initial='/inscricao',
179 widget=HiddenInput())
180 urlInforma = forms.CharField(max_length=60, initial='/inscricao',
181 widget=HiddenInput())
182 nome = forms.CharField(max_length=60, widget=HiddenInput())
183 endereco = forms.CharField(max_length=60, widget=HiddenInput())
184 cidade = forms.CharField(max_length=18, widget=HiddenInput())
185 uf = forms.CharField(max_length=2, widget=HiddenInput())
186 cep = forms.CharField(max_length=8, widget=HiddenInput())
187 msgLoja = forms.CharField(max_length=480,
188 initial='Nao receber apos a data de vencimento',
189 widget=HiddenInput())