conferindo senha
[cascardo/eventmanager.git] / views.py
index 3acdc8b..677bbc0 100644 (file)
--- a/views.py
+++ b/views.py
@@ -23,6 +23,7 @@ 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.db import transaction
 
 from eventmanager.decorators import enable_login_form
 from eventmanager.forms import *
@@ -58,8 +59,9 @@ def index(request):
     return build_response(request, 'index.html')
 
 
+@transaction.commit_manually
 @enable_login_form
-def cadastro(request):
+def cadastro_palestrante(request):
     c = {}
     if request.POST:
         # django's newforms lib requires a new instance of a form to be bounded
@@ -70,9 +72,7 @@ def cadastro(request):
             badattr = form.errors
             wrong = False
 
-            if not cd['telefone_comercial'] and \
-               not cd['telefone_residencial'] and \
-               not cd['telefone_celular']:
+            if not cd['telefone'] and not cd['celular']:
                 badattr['telefone_comercial'] = ['Algum número de telefone '
                                                  'precisa ser informado']
                 wrong = True
@@ -82,9 +82,15 @@ def cadastro(request):
                 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
 
+            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='palestrantes')[0]
 
@@ -98,9 +104,8 @@ def cadastro(request):
 
                 p.nome = cd['nome_completo']
                 p.email = cd['email']
-                p.telefone_comercial = cd['telefone_comercial']
-                p.telefone_residencial = cd['telefone_residencial']
-                p.telefone_celular = cd['telefone_celular']
+                p.telefone = cd['telefone']
+                p.celular = cd['celular']
                 p.rua = cd['rua']
                 p.numero = cd['numero']
                 p.bairro = cd['bairro']
@@ -122,6 +127,7 @@ def cadastro(request):
                 errors = manipulator.get_validation_errors(fakepost)
                 got_user = manipulator.get_user()
                 login(request, got_user)
+                transaction.commit()
     else:
         form = CadastroPalestrante()
     c.update({'form': form})
@@ -139,18 +145,19 @@ def inscricao(request):
 
 @login_required
 @user_passes_test(lambda u:u.palestrante_set.count() == 1, login_url='/')
-def inscrever_palestra(request):
+def submeter_trabalho(request):
     c = {}
     if request.POST:
-        form = InscreverPalestra(request.POST)
+        form = SubmeterTrabalho(request.POST)
         if form.is_valid():
             cd = form.cleaned_data
-            p = Palestra()
+            p = Trabalho()
             p.titulo = cd['titulo']
-            p.tema = cd['tema']
-            p.categoria = CategoriaPalestra.objects.get(pk=cd['categoria'])
+            p.tipo = TipoTrabalho.objects.get(pk=cd['tipo'])
+            p.categoria = CategoriaTrabalho.objects.get(pk=cd['categoria'])
             p.descricao_curta = cd['descricao_curta']
             p.descricao_longa = cd['descricao_longa']
+            p.recursos = cd['recursos']
             p.evento = Evento.objects.get(pk=1) # let the hammer play arround!
             p.save()
 
@@ -161,7 +168,7 @@ def inscrever_palestra(request):
                 p.palestrante.add(up)
             c.update({'ok': 1})
     else:
-        form = InscreverPalestra()
+        form = SubmeterTrabalho()
     c.update({'form': form})
     return build_response(request, 'inscrever_palestra.html', c)
 
@@ -176,9 +183,8 @@ def meus_trabalhos(request):
         c = {'palestrante': 0}
         return build_response(request, 'meus_trabalhos.html', c)
 
-    palestras = Palestra.objects.filter(palestrante=p)
-    minicursos = MiniCurso.objects.filter()
-    c = {'palestras': palestras, 'minicursos': minicursos, 'palestrante': 1}
+    t = Trabalho.objects.filter(palestrante=p)
+    c = {'trabalhos': t, 'palestrante': 1}
     return build_response(request, 'meus_trabalhos.html', c)