1 # -*- coding: utf8; -*-
3 Copyright (C) 2007 Lincoln de Sousa <lincoln@archlinux-br.org>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public
16 License along with this program; if not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
20 from django.shortcuts import render_to_response
21 from django.template import RequestContext, Context
22 from django.contrib.auth.decorators import login_required
23 from django.contrib.auth.models import Group, User
24 from django.contrib.auth.forms import AuthenticationForm
25 from django.contrib.auth import login
27 from eventmanager.decorators import enable_login_form
28 from eventmanager.forms import *
29 from eventmanager.conteudo.models import Noticia, Menu, Secao
30 from eventmanager.eventos.models import *
32 def build_response(request, template, extra={}):
34 Shortcut to build a response based on a C{template} and build a standard
35 context to this template. This context contains news itens, a list of menus
36 and a list of sections to be shown on index. But don't worry, this context
37 is extensible through the C{extra} parameter.
39 @param template: Contains the name of a template found in django
41 @type template: C{str}
43 @param extra: Extra variables to be passed to the context being built.
46 news = Noticia.objects.order_by('-data_criacao')
47 menus = Menu.objects.all()
48 index_sections = Secao.objects.filter(index=True)
49 c = {'news': news, 'menu': menus,
50 'index_sections': index_sections}
52 return render_to_response(template, Context(c),
53 context_instance=RequestContext(request))
58 return build_response(request, 'index.html')
62 def cadastro(request):
65 # django's newforms lib requires a new instance of a form to be bounded
66 # with data, to be validated and used.
67 form = CadastroPalestrante(request.POST)
69 cd = form.cleaned_data
73 if not cd['telefone_comercial'] and \
74 not cd['telefone_residencial'] and \
75 not cd['telefone_celular']:
76 badattr['telefone_comercial'] = ['Algum número de telefone '
77 'precisa ser informado']
80 # don't save duplicated users...
82 User.objects.get(username=cd['nome_usuario'])
83 badattr['nome_usuario'] = ['Este nome de usuário já existe!']
85 except User.DoesNotExist:
89 group = Group.objects.get_or_create(name='palestrantes')[0]
91 user = User(username=cd['nome_usuario'], email=cd['email'])
92 user.set_password(cd['senha'])
94 user.groups.add(group)
99 p.nome = cd['nome_completo']
100 p.email = cd['email']
101 p.telefone_comercial = cd['telefone_comercial']
102 p.telefone_residencial = cd['telefone_residencial']
103 p.telefone_celular = cd['telefone_celular']
105 p.numero = cd['numero']
106 p.bairro = cd['bairro']
107 p.cidade = cd['cidade']
109 p.minicurriculo = cd['minicurriculo']
112 for i in cd['area_interesse']:
113 p.area_interesse.add(i)
117 fakepost = request.POST.copy()
118 fakepost['username'] = cd['nome_usuario']
119 fakepost['password'] = cd['senha']
121 manipulator = AuthenticationForm(request)
122 errors = manipulator.get_validation_errors(fakepost)
123 got_user = manipulator.get_user()
124 login(request, got_user)
126 form = CadastroPalestrante()
127 c.update({'form': form})
128 return build_response(request, 'cadastro.html', c)
132 def inscricao(request):
134 form = Inscricao(request.POST)
137 return build_response(request, 'inscricao.html', {'form': form})
141 def inscrever_palestra(request):
143 form = InscreverPalestra(request.POST)
145 cd = form.cleaned_data
147 p.titulo = cd['titulo']
149 p.categoria = CategoriaPalestra.objects.get(pk=cd['categoria'])
150 p.descricao_curta = cd['descricao_curta']
151 p.descricao_longa = cd['descricao_longa']
152 p.evento = Evento.objects.get(pk=1) # let the hammer play arround!
155 up = User.objects.get(pk=request.user.id)
158 form = InscreverPalestra()
159 return build_response(request, 'inscrever_palestra.html', {'form': form})