From 85ae73636a650eacc7edf00f5163c467b97bffb9 Mon Sep 17 00:00:00 2001 From: Lincoln de Sousa Date: Mon, 24 Sep 2007 19:04:55 -0300 Subject: [PATCH] =?utf8?q?reformula=C3=A7=C3=A3o=20dos=20formul=C3=A1rios?= =?utf8?q?=20de=20inscri=C3=A7=C3=A3o...?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- forms.py | 41 +++++++++------------ templates/inscricao.html | 18 ++-------- templates/inscricao_caravana.html | 26 ++++++++++++++ templates/inscricao_individual.html | 21 +++++++++++ urls.py | 4 +++ views.py | 55 ++++++++++++++++++++++------- 6 files changed, 113 insertions(+), 52 deletions(-) create mode 100644 templates/inscricao_caravana.html create mode 100644 templates/inscricao_individual.html diff --git a/forms.py b/forms.py index cac8fd6..f2f0502 100644 --- a/forms.py +++ b/forms.py @@ -52,7 +52,6 @@ class SubmeterTrabalho(forms.Form): 'ex.: Computadores, softwares, etc. Máximo de 300 caracteres.') outros_palestrantes = forms.MultipleChoiceField(required=0) - class CadastroPalestrante(forms.Form): nome_completo = forms.CharField(max_length=100) nome_usuario = forms.CharField(max_length=100) @@ -77,7 +76,6 @@ class CadastroPalestrante(forms.Form): cidade = forms.CharField(max_length=100) uf = forms.ChoiceField(choices=STATE_CHOICES) - class EditarPalestrante(forms.Form): nome = forms.CharField(max_length=100, label='Nome completo') email = forms.CharField(max_length=100) @@ -98,19 +96,27 @@ class EditarPalestrante(forms.Form): 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 InscricaoCaravana(forms.Form): + 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>') -class Inscricao(forms.Form): +class InscricaoBase(forms.Form): 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) + 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) rua = forms.CharField(max_length=100) numero = forms.CharField(max_length=10, label='Número') bairro = forms.CharField(max_length=100) @@ -119,25 +125,10 @@ class Inscricao(forms.Form): pagina_pessoal = forms.CharField(max_length=100) telefone = forms.CharField(max_length=100) - estudante = forms.BooleanField(required=False) - - first_step = forms.CharField(max_length=1, - widget=forms.HiddenInput, initial='1') - - -class InscricaoEstudante(forms.Form): - post2 = forms.CharField(max_length=1, - widget=forms.HiddenInput, initial='1') - estudante = forms.CharField(max_length=1, - widget=forms.HiddenInput, initial='1') - - instituicao = forms.CharField(max_length=100) - curso = forms.CharField(max_length=100) - periodo = forms.CharField(max_length=100) -class InscricaoNormal(forms.Form): - empresa = forms.CharField(max_length=100) - post2 = forms.CharField(max_length=1, - widget=forms.HiddenInput, initial='1') +class Inscricao(InscricaoBase): + comercial = forms.BooleanField(required=False) +class InscricaoCoordenador(InscricaoBase): + pass diff --git a/templates/inscricao.html b/templates/inscricao.html index 1415736..41cc24b 100644 --- a/templates/inscricao.html +++ b/templates/inscricao.html @@ -1,21 +1,9 @@ {% extends "base.html" %} {% block content %} -

Inscrição do participante

+

Inscrição

-{% if ok %} - -
-

Cadastro efetuado com sucesso, você já foi autenticado.

-
- -{% else %} - -
- {{ form.as_p }} - -
- -{% endif %} +

Inscrição Individual

+

Inscrição de Caravana

{% endblock %} diff --git a/templates/inscricao_caravana.html b/templates/inscricao_caravana.html new file mode 100644 index 0000000..e3b529d --- /dev/null +++ b/templates/inscricao_caravana.html @@ -0,0 +1,26 @@ +{% extends "base.html" %} +{% block content %} + +

Inscrição de Caravana

+ +{% if ok %} + +
+

Cadastro efetuado com sucesso, você já foi autenticado.

+
+ +{% else %} + +
+

Dados do coordenador da caravana

+ {{ form_coordenador.as_p }} + +

Dados dos participantes da caravana

+ {{ form.as_p }} + + +
+ +{% endif %} + +{% endblock %} diff --git a/templates/inscricao_individual.html b/templates/inscricao_individual.html new file mode 100644 index 0000000..7f92d20 --- /dev/null +++ b/templates/inscricao_individual.html @@ -0,0 +1,21 @@ +{% extends "base.html" %} +{% block content %} + +

Inscrição do Individual

+ +{% if ok %} + +
+

Cadastro efetuado com sucesso, você já foi autenticado.

+
+ +{% else %} + +
+ {{ form.as_p }} + +
+ +{% endif %} + +{% endblock %} diff --git a/urls.py b/urls.py index cf93987..5d87e46 100644 --- a/urls.py +++ b/urls.py @@ -28,7 +28,11 @@ urlpatterns = patterns('', (r'^admin/', include('django.contrib.admin.urls')), (r'^logout/', 'django.contrib.auth.views.logout', {'next_page': '/'}), + (r'^inscricao/', views.inscricao), + (r'^inscricao_individual/', views.inscricao_individual), + (r'^inscricao_caravana/', views.inscricao_caravana), + (r'^submeter_trabalho/', views.submeter_trabalho), (r'^cadastro_palestrante/', views.cadastro_palestrante), (r'^meus_trabalhos/', views.meus_trabalhos), diff --git a/views.py b/views.py index d655df2..ee7b1b3 100644 --- a/views.py +++ b/views.py @@ -148,22 +148,53 @@ def cadastro_palestrante(request): @enable_login_form def inscricao(request): - post = request.POST - post2 = 'post2' in post and post or None + return build_response(request, 'inscricao.html') - # exibe o formulário de inscrição de estudantes. - if 'estudante' in post: - form = InscricaoEstudante(post2) - # inscrição normal (sem ser estudante) - elif not 'estudante' in post and ('first_step' in post or 'empresa' in post): - form = InscricaoNormal(post2) +@enable_login_form +@transaction.commit_manually +def inscricao_individual(request): + form = Inscricao(request.POST or None) + ok = False + if request.POST and form.is_valid(): + cd = form.cleaned_data + badattr = form.errors + wrong = False - # primeiro passo... - else: - form = Inscricao(post or None) + # don't save duplicated users... + try: + User.objects.get(username=cd['nome_usuario']) + badattr['nome_usuario'] = ['Este nome de usuário já existe!'] + wrong = True + transaction.rollback() + except User.DoesNotExist: + pass - return build_response(request, 'inscricao.html', {'form': form}) + if cd['senha'] != cd['senha_2']: + badattr['senha_2'] = ['A senha não confere'] + wrong = True + transaction.rollback() + + if not wrong: + group = Group.objects.get_or_create(name='participantes')[0] + + user = User(username=cd['nome_usuario'], email=cd['email']) + user.set_password(cd['senha']) + user.is_active = False + user.save() + user.groups.add(group) + + transaction.commit() + + return build_response(request, 'inscricao_individual.html', {'form': form}) + + +@enable_login_form +def inscricao_caravana(request): + form_coordenador = InscricaoCoordenador(request.POST or None) + form = InscricaoCaravana(request.POST or None) + return build_response(request, 'inscricao_caravana.html', + {'form_coordenador': form_coordenador, 'form': form}) @login_required -- 2.20.1