X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Feventmanager.git;a=blobdiff_plain;f=forms.py;h=1f10f13c543e7f966507bf52cd5cfee2ba54c34c;hp=ff6624925d85b6636959950cb074c5d765701867;hb=838f1585f18722b3913b70363ca73a84305802f9;hpb=167d8b2bec92c0040627ab6887f504c515730296 diff --git a/forms.py b/forms.py index ff66249..1f10f13 100644 --- a/forms.py +++ b/forms.py @@ -18,13 +18,33 @@ Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. """ from django import newforms as forms -from django.newforms.widgets import Textarea, PasswordInput +from django.newforms import ValidationError +from django.newforms.widgets import Textarea, PasswordInput, HiddenInput +from django.contrib.auth.models import User from eventmanager.eventos.models import \ TipoTrabalho, CategoriaTrabalho, Palestrante, STATE_CHOICES MKCHOICES = lambda K, xid=-1:[(x.id, str(x)) for x in K.objects.all() \ if xid != x.id] +class LoginBase(forms.Form): + nome_usuario = forms.CharField(max_length=100) + senha = forms.CharField(max_length=100, widget=PasswordInput()) + senha_2 = forms.CharField(max_length=100, widget=PasswordInput(), + label='Conferir Senha') + + def clean_nome_usuario(self): + try: + User.objects.get(username=self.cleaned_data['nome_usuario']) + raise ValidationError('Já existe um usuário com esse nome') + except User.DoesNotExist: + return self.cleaned_data['nome_usuario'] + + def clean_senha_2(self): + if self.cleaned_data['senha'] != self.cleaned_data['senha_2']: + raise ValidationError('A confirmação não confere com a senha') + return self.cleaned_data['senha_2'] + class SubmeterTrabalho(forms.Form): def __init__(self, request, *args, **kwargs): super(SubmeterTrabalho, self).__init__(*args, **kwargs) @@ -52,13 +72,8 @@ class SubmeterTrabalho(forms.Form): 'ex.: Computadores, softwares, etc. Máximo de 300 caracteres.') outros_palestrantes = forms.MultipleChoiceField(required=0) - -class CadastroPalestrante(forms.Form): +class CadastroPalestrante(LoginBase): nome_completo = forms.CharField(max_length=100) - nome_usuario = forms.CharField(max_length=100) - senha = forms.CharField(max_length=100, widget=PasswordInput()) - senha_2 = forms.CharField(max_length=100, widget=PasswordInput(), - label='Conferir Senha') email = forms.CharField(max_length=100) telefone = forms.CharField(required=False) @@ -66,10 +81,10 @@ class CadastroPalestrante(forms.Form): instituicao = forms.CharField(max_length=100, label='Instituição') minicurriculo = forms.CharField(widget=Textarea(), max_length=250, label='Mini Currículo', - help_text='Este mini currículo será utilizado no material de divulgação' - 'e no site. Máximo de 250 caracteres.') + help_text='Este mini currículo será utilizado no material de divulgação ' + 'e no sítio. Máximo de 250 caracteres.') curriculo = forms.CharField(widget=Textarea(), max_length=6000, label='Currículo', - help_text='Este currículo será utilizado para avaliação do palestrante.' + help_text='Este currículo será utilizado para avaliação do palestrante. ' 'Máximo de 6000 caracteres.') rua = forms.CharField(max_length=100) numero = forms.CharField(max_length=10, label='Número') @@ -77,6 +92,11 @@ class CadastroPalestrante(forms.Form): cidade = forms.CharField(max_length=100) uf = forms.ChoiceField(choices=STATE_CHOICES) + def clean_celular(self): + if not self.cleaned_data['telefone'] and \ + not self.cleaned_data['celular']: + raise ValidationError('Algum número de precisa ser preenchido') + return self.cleaned_data['celular'] class EditarPalestrante(forms.Form): nome = forms.CharField(max_length=100, label='Nome completo') @@ -89,31 +109,81 @@ class EditarPalestrante(forms.Form): minicurriculo = forms.CharField(widget=Textarea(), max_length=250, label='Mini Currículo', help_text='Este mini currículo será utilizado no material de divulgação' 'e no site. Máximo de 250 caracteres.') - curriculo = forms.CharField(widget=Textarea(), max_length=1000, label='Currículo', + curriculo = forms.CharField(widget=Textarea(), max_length=6000, label='Currículo', help_text='Este currículo será utilizado para avaliação do palestrante.' - 'Máximo de 1000 caracteres.') + 'Máximo de 6000 caracteres.') rua = forms.CharField(max_length=100) numero = forms.CharField(max_length=10, label='Número') bairro = forms.CharField(max_length=100) cidade = forms.CharField(max_length=100) uf = forms.ChoiceField(choices=STATE_CHOICES) - class EditarSenha(forms.Form): senha_atual = forms.CharField(max_length=100, widget=PasswordInput()) nova_senha = forms.CharField(max_length=100, widget=PasswordInput()) nova_senha_2 = forms.CharField(max_length=100, widget=PasswordInput(), label='Conferir Senha') - -class Inscricao(forms.Form): +class InscricaoBase(LoginBase): nome_completo = forms.CharField(max_length=100) - cpf = forms.CharField(max_length=100) - email = forms.CharField(max_length=100) + rg = forms.CharField(max_length=100) + email = forms.CharField(max_length=100) rua = forms.CharField(max_length=100) numero = forms.CharField(max_length=10, label='Número') bairro = forms.CharField(max_length=100) cidade = forms.CharField(max_length=100) uf = forms.ChoiceField(choices=STATE_CHOICES) - + cep = forms.CharField(max_length=8, help_text='Somente números') + telefone = forms.CharField(max_length=100) + home_page = forms.CharField(max_length=100, label='Página Pessoal', + required=False) + +class Inscricao(InscricaoBase): + inscricao_comercial = forms.BooleanField(required=False, + label='Inscrição Comercial') + cpf_cnpj = forms.CharField(max_length=20, required=False, label='CPF/CNPJ', + help_text='Somente necessário para a inscrição comercial') + + def clean_cpf_cnpj(self): + cpf_cnpj = self.cleaned_data['cpf_cnpj'] + if self.cleaned_data['inscricao_comercial'] and not cpf_cnpj: + raise ValidationError('Você escolheu a inscrição comercial, ' + 'portanto este campo se torna obrigatório') + return cpf_cnpj + +class InscricaoCaravana(InscricaoBase): + lista_nomes = forms.CharField(label='Lista de nomes', + widget=forms.Textarea(), help_text='Um participante por linha, ' + 'informando nome completo e email no seguine formato: ' + 'Nome Completo <email@server.domain>') + + def clean_lista_nomes(self): + nomes = self.cleaned_data['lista_nomes'] + if len([x for x in nomes.split('\n') if x]) < 10: + raise ValidationError('A caravana precisa de pelo menos 10 ' + 'participantes.') + return nomes + +class Boleto(forms.Form): + # Field names are in mixedCase because of bb's sistem request =/ + idConv = forms.CharField(max_length=6, initial='303366', + widget=HiddenInput()) + refTran = forms.CharField(max_length=17, + widget=HiddenInput()) + tpPagamento = forms.CharField(max_length=2, initial='21', + widget=HiddenInput()) + valor = forms.CharField(max_length=15, widget=HiddenInput()) + dtVenc = forms.CharField(max_length=8, widget=HiddenInput()) + urlRetorno = forms.CharField(max_length=60, initial='/inscricao', + widget=HiddenInput()) + urlInforma = forms.CharField(max_length=60, initial='/inscricao', + widget=HiddenInput()) + nome = forms.CharField(max_length=60, widget=HiddenInput()) + endereco = forms.CharField(max_length=60, widget=HiddenInput()) + cidade = forms.CharField(max_length=18, widget=HiddenInput()) + uf = forms.CharField(max_length=2, widget=HiddenInput()) + cep = forms.CharField(max_length=8, widget=HiddenInput()) + msgLoja = forms.CharField(max_length=480, + initial='Nao receber apos a data de vencimento', + widget=HiddenInput())