"""
from django.shortcuts import render_to_response
from django.template import RequestContext, Context
-from django.contrib.auth.decorators import login_required
+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 eventmanager.eventos.models import *
def build_response(request, template, extra={}):
+ """
+ Shortcut to build a response based on a C{template} and build a standard
+ context to this template. This context contains news itens, a list of menus
+ and a list of sections to be shown on index. But don't worry, this context
+ is extensible through the C{extra} parameter.
+
+ @param template: Contains the name of a template found in django
+ C{TEMPLATE_DIRS}
+ @type template: C{str}
+
+ @param extra: Extra variables to be passed to the context being built.
+ @type extra: C{dict}
+ """
news = Noticia.objects.order_by('-data_criacao')
menus = Menu.objects.all()
index_sections = Secao.objects.filter(index=True)
@enable_login_form
def cadastro(request):
+ c = {}
if request.POST:
# django's newforms lib requires a new instance of a form to be bounded
# with data, to be validated and used.
form = CadastroPalestrante(request.POST)
if form.is_valid():
cd = form.cleaned_data
+ badattr = form.errors
wrong = False
- # XXX: really ugly hack to use django validation machinary...
- badattr = form._BaseForm__errors
-
if not cd['telefone_comercial'] and \
not cd['telefone_residencial'] and \
not cd['telefone_celular']:
if not wrong:
group = Group.objects.get_or_create(name='palestrantes')[0]
+ user = User(username=cd['nome_usuario'], email=cd['email'])
+ user.set_password(cd['senha'])
+ user.save()
+ user.groups.add(group)
+
p = Palestrante()
- p.user = User(username=cd['nome_usuario'], email=cd['email'])
- p.user.set_password(cd['senha'])
- p.user.save()
- p.user.groups.add(group)
+ p.usuario = user
p.nome = cd['nome_completo']
p.email = cd['email']
p.minicurriculo = cd['minicurriculo']
p.save()
- for i in cd['area_interesse']:
+ for i in cd.get('area_interesse', []):
p.area_interesse.add(i)
c.update({'ok': 1})
login(request, got_user)
else:
form = CadastroPalestrante()
- return build_response(request, 'cadastro.html', {'form': form})
+ c.update({'form': form})
+ return build_response(request, 'cadastro.html', c)
@enable_login_form
@login_required
+@user_passes_test(lambda u:u.palestrante_set.count() == 1, login_url='/')
def inscrever_palestra(request):
+ c = {}
if request.POST:
form = InscreverPalestra(request.POST)
if form.is_valid():
p.evento = Evento.objects.get(pk=1) # let the hammer play arround!
p.save()
- up = User.objects.get(pk=request.user.id)
- p.palestrante.add()
+ logged_in = request.user.palestrante_set.get()
+ p.palestrante.add(logged_in)
+ for i in cd.get('outros_palestrantes', []):
+ up = Palestrante.objects.get(pk=int(i))
+ p.palestrante.add(up)
+ c.update({'ok': 1})
else:
form = InscreverPalestra()
- return build_response(request, 'inscrever_palestra.html', {'form': form})
+ c.update({'form': form})
+ return build_response(request, 'inscrever_palestra.html', c)
+
+
+@login_required
+@user_passes_test(lambda u:u.palestrante_set.count() == 1, login_url='/')
+def meus_trabalhos(request):
+ try:
+ p = Palestrante.objects.get(usuario=request.user)
+ except Palestrante.DoesNotExist:
+ # não palestrante...
+ 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}
+ return build_response(request, 'meus_trabalhos.html', c)
+
+
+@enable_login_form
+def chamada_trabalhos(request):
+ return build_response(request, 'chamada_trabalhos.html')