melhorias no formulário de inscrição e fazendo também a confirmação via email na...
authorLincoln de Sousa <lincoln@archlinux-br.org>
Tue, 11 Sep 2007 19:14:03 +0000 (16:14 -0300)
committerLincoln de Sousa <lincoln@archlinux-br.org>
Tue, 11 Sep 2007 19:14:03 +0000 (16:14 -0300)
forms.py
templates/cadastro.html
templates/inscricao.html
views.py

index 7890fc6..d33a8c5 100644 (file)
--- a/forms.py
+++ b/forms.py
@@ -116,4 +116,28 @@ class Inscricao(forms.Form):
     bairro = forms.CharField(max_length=100)
     cidade = forms.CharField(max_length=100)
     uf = forms.ChoiceField(choices=STATE_CHOICES)
     bairro = forms.CharField(max_length=100)
     cidade = forms.CharField(max_length=100)
     uf = forms.ChoiceField(choices=STATE_CHOICES)
+    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')
 
 
index 9027481..4b7ca0e 100644 (file)
@@ -6,9 +6,11 @@
 {% if ok %}
 
 <div class="confirmation">
 {% if ok %}
 
 <div class="confirmation">
-    <p>Cadastro efetuado com sucesso, você já foi autenticado.</p>
+    <p>Cadastro efetuado com sucesso!</p>
 
 
-    <p>Use o menu que apareceu para cadastrar uma palestra ou um minicurso</p>
+    <p>Foi enviado um email de confirmação para o endereço {{ email }}.</p>
+    <p>Siga as instruções do email para concluir o cadastro e prosseguir
+    com a submissão de trabalhos.</p>
 </div>
 
 {% else %}
 </div>
 
 {% else %}
index 33e3de0..1415736 100644 (file)
@@ -13,7 +13,7 @@
 
 <form id="cadastro" method="post" action=".">
     {{ form.as_p }}
 
 <form id="cadastro" method="post" action=".">
     {{ form.as_p }}
-    <input type="submit" value="Ok!" />
+    <input type="submit" value="Próximo >>" />
 </form>
 
 {% endif %}
 </form>
 
 {% endif %}
index f077444..7639c57 100644 (file)
--- a/views.py
+++ b/views.py
@@ -18,17 +18,20 @@ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.
 """
 from django.shortcuts import render_to_response
 Boston, MA 02111-1307, USA.
 """
 from django.shortcuts import render_to_response
-from django.template import RequestContext, Context
+from django.template import RequestContext, Context, loader
 from django.contrib.auth.decorators import login_required, user_passes_test
 from django.contrib.auth.models import Group, User
 from django.contrib.auth.decorators import login_required, user_passes_test
 from django.contrib.auth.models import Group, User
-from django.contrib.auth.forms import AuthenticationForm
-from django.contrib.auth import login
+from django.core.mail import EmailMessage
 from django.db import transaction
 from django.db import transaction
+from django.http import get_host
 
 from eventmanager.decorators import enable_login_form
 from eventmanager.forms import *
 from eventmanager.conteudo.models import Noticia, Menu, Secao
 from eventmanager.eventos.models import *
 
 from eventmanager.decorators import enable_login_form
 from eventmanager.forms import *
 from eventmanager.conteudo.models import Noticia, Menu, Secao
 from eventmanager.eventos.models import *
+import sha
+
+FROM_EMAIL = 'Emsl 2007 <noreply@minaslivre.org>'
 
 def build_response(request, template, extra={}):
     """
 
 def build_response(request, template, extra={}):
     """
@@ -93,6 +96,7 @@ def cadastro_palestrante(request):
 
             user = User(username=cd['nome_usuario'], email=cd['email'])
             user.set_password(cd['senha'])
 
             user = User(username=cd['nome_usuario'], email=cd['email'])
             user.set_password(cd['senha'])
+            user.is_active = False
             user.save()
             user.groups.add(group)
 
             user.save()
             user.groups.add(group)
 
@@ -116,23 +120,44 @@ def cadastro_palestrante(request):
             for i in cd.get('area_interesse', []):
                 p.area_interesse.add(i)
 
             for i in cd.get('area_interesse', []):
                 p.area_interesse.add(i)
 
-            fakepost = request.POST.copy()
-            fakepost['username'] = cd['nome_usuario']
-            fakepost['password'] = cd['senha']
+            pid = p.id
+            md5_email = sha.new(cd['emai']).hexdigest()
+            email = '%s <%s>' % (cd['nome_completo'], cd['email'])
+            link = '%s/verificar?c=%s&c1=%s' % (get_host(request),
+                    pid, md5_email)
+            t = loader.get_template('email-palestrante.html')
+            c = Context(dict(fulano=['nome_usuario'], link=link))
+            try:
+                m = EmailMessage('Encontro Mineiro de Software Livre',
+                    t.render(c), FROM_EMAIL, [email])
+                m.send()
+            except Exception:
+                transaction.rollback()
+            else:
+                ok = True
+                transaction.commit()
 
 
-            manipulator = AuthenticationForm(request)
-            errors = manipulator.get_validation_errors(fakepost)
-            got_user = manipulator.get_user()
-            login(request, got_user)
-            transaction.commit()
-            ok = True
     c = {'form': form, 'ok': ok}
     return build_response(request, 'cadastro.html', c)
 
 
 @enable_login_form
 def inscricao(request):
     c = {'form': form, 'ok': ok}
     return build_response(request, 'cadastro.html', c)
 
 
 @enable_login_form
 def inscricao(request):
-    form = Inscricao(request.POST or None)
+    post = request.POST
+    post2 = 'post2' in post and post or None
+
+    # 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 or 'empresa' in post:
+        form = InscricaoNormal(post2)
+
+    # primeiro passo...
+    else:
+        form = Inscricao(post or None)
+
     return build_response(request, 'inscricao.html', {'form': form})
 
 
     return build_response(request, 'inscricao.html', {'form': form})