1 # -*- coding: utf-8; -*-
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, get_object_or_404
21 from django.template import RequestContext, Context, loader
22 from django.contrib.auth.decorators import login_required, user_passes_test
23 from django.contrib.auth.models import Group, User
24 from django.contrib.auth import authenticate, login
25 from django.newforms import form_for_instance
26 from django.core.mail import EmailMessage
27 from django.db import transaction
28 from django.http import get_host
29 from django.conf import settings
31 from eventmanager.decorators import enable_login_form
32 from eventmanager.conteudo.models import Noticia, Menu, Secao
33 from eventmanager.eventos.models import *
35 from django.newforms import form_for_instance
37 from eventmanager.forms import *
39 from datetime import datetime
42 FROM_EMAIL = 'Emsl 2007 <noreply@minaslivre.org>'
43 >>>>>>> 11faa820abeb69b688db5076aa4c1cc663dfeb53/views.py
45 def build_response(request, template, extra={}):
47 Shortcut to build a response based on a C{template} and build a standard
48 context to this template. This context contains news itens, a list of menus
49 and a list of sections to be shown on index. But don't worry, this context
50 is extensible through the C{extra} parameter.
52 @param template: Contains the name of a template found in django
54 @type template: C{str}
56 @param extra: Extra variables to be passed to the context being built.
59 news = Noticia.objects.order_by('-data_criacao')
60 menus = Menu.objects.all()
61 index_sections = Secao.objects.filter(index=True)
62 login_failed = 'login_failed' in request.GET
63 c = {'news': news, 'menu': menus,
64 'index_sections': index_sections,
65 'login_failed': login_failed}
67 return render_to_response(template, Context(c),
68 context_instance=RequestContext(request))
73 return build_response(request, 'index.html')
76 @transaction.commit_manually
78 def cadastro_palestrante(request):
79 form = CadastroPalestrante(request.POST or None)
82 if request.POST and form.is_valid():
83 cd = form.cleaned_data
86 group = Group.objects.get_or_create(name='palestrantes')[0]
88 user = User(username=cd['nome_usuario'], email=cd['email'])
89 user.set_password(cd['senha'])
90 user.is_active = False
92 user.groups.add(group)
97 p.nome = cd['nome_completo']
99 p.telefone = cd['telefone']
100 p.celular = cd['celular']
101 p.instituicao = cd['instituicao']
103 p.numero = cd['numero']
104 p.bairro = cd['bairro']
105 p.cidade = cd['cidade']
107 p.minicurriculo = cd['minicurriculo']
108 p.curriculo = cd['curriculo']
111 for i in cd.get('area_interesse', []):
112 p.area_interesse.add(i)
115 md5_email = sha.new(cd['email']).hexdigest()
116 email = '%s <%s>' % (cd['nome_completo'], cd['email'])
117 link = '%s/verificar?c=%s&c1=%s' % (get_host(request),
119 t = loader.get_template('email-palestrante.html')
120 ec = Context(dict(fulano=['nome_usuario'], link=link))
122 # to be shown in template...
123 c.update({'email': email})
125 # XXX: maybe is not a good so prety put things hardcoded =(
126 m = EmailMessage('Encontro Mineiro de Software Livre',
127 t.render(ec), FROM_EMAIL, [email])
131 ['Desculpe mas não pude enviar o email de confirmação']
132 transaction.rollback()
138 return build_response(request, 'cadastro.html', c)
142 def inscricao(request):
143 return build_response(request, 'inscricao.html')
147 @transaction.commit_manually
148 def inscricao_individual(request):
149 form = Inscricao(request.POST or None)
151 if request.POST and form.is_valid():
152 cd = form.cleaned_data
153 group = Group.objects.get_or_create(name='participantes')[0]
155 user = User(username=cd['nome_usuario'], email=cd['email'])
156 user.set_password(cd['senha'])
157 user.is_active = False
159 user.groups.add(group)
162 p.nome = cd['nome_completo']
164 p.email = cd['email']
166 p.numero = cd['numero']
167 p.bairro = cd['bairro']
168 p.cidade = cd['cidade']
172 p.telefone = cd['telefone']
173 p.home_page = cd['home_page']
174 p.comercial = cd['inscricao_comercial']
175 p.cpf_cnpj = cd['cpf_cnpj']
178 u = authenticate(username=cd['nome_usuario'], password=cd['senha'])
183 c = {'form': form, 'ok': ok}
184 return build_response(request, 'inscricao_individual.html', c)
188 @transaction.commit_manually
189 def inscricao_caravana(request):
190 form = InscricaoCaravana(request.POST or None)
192 if request.POST and form.is_valid():
193 cd = form.cleaned_data
194 group = Group.objects.get_or_create(name='participantes')[0]
196 user = User(username=cd['nome_usuario'], email=cd['email'])
197 user.set_password(cd['senha'])
198 user.is_active = False
200 user.groups.add(group)
204 p.nome = cd['nome_completo']
206 p.email = cd['email']
208 p.numero = cd['numero']
209 p.bairro = cd['bairro']
210 p.cidade = cd['cidade']
214 p.telefone = cd['telefone']
215 p.home_page = cd['home_page']
216 p.comercial = False # yeah, always false!
222 c.participantes = cd['lista_nomes']
226 u = authenticate(username=cd['nome_usuario'], password=cd['senha'])
230 c = {'form': form, 'ok': ok}
231 return build_response(request, 'inscricao_caravana.html', c)
235 def inscricao_boleto(request):
236 # dynamic values of the form
238 today = datetime.date(now)
239 first_date = datetime.date(datetime(2007, 10, 12))
242 p = request.user.participante_set.get()
243 ca = p.caravana_set.all() and p.caravana_set.get()
248 # o número refTran deve ser gerado a cada novo boleto e deve ser único,
249 # mesmo para os testes
250 refs = [x.refbanco for x in Participante.objects.all()]
252 while new_ref in refs or new_ref <= settings.MIN_REF_TRAN:
255 # este dado precisa ser persistente para que possa ser comparado logo acima
261 initial['refTran'] = '1458197%s' % str(new_ref).zfill(10)
262 if today < first_date:
263 initial['dtVenc'] = '12102007'
265 initial['valor'] = '3500'
267 initial['valor'] = '8000'
269 # caso seja uma caravana...
270 if ca and len(ca.parsed_participantes()) >= 10:
271 # sim, o valor aqui é 25 -- Desconto
272 initial['valor'] = '%s00' % (len(ca.parsed_participantes()) * 25)
273 c.update({'caravana': 1})
275 initial['valor'] = '5000'
276 initial['dtVenc'] = '17102007'
278 initial['nome'] = p.nome
279 initial['endereco'] = '%s, %s - %s' % (p.rua, p.numero, p.bairro)
280 initial['cidade'] = p.cidade
282 initial['cep'] = p.cep
284 form = Boleto(request.POST or None, initial=initial)
285 c.update({'form': form})
287 return build_response(request, 'inscricao_boleto.html', c)
291 @user_passes_test(lambda u:u.palestrante_set.count() == 1, login_url='/')
292 def submeter_trabalho(request):
293 form = SubmeterTrabalho(request, request.POST or None)
296 if request.POST and form.is_valid():
297 cd = form.cleaned_data
299 t.titulo = cd['titulo']
300 t.tipo = TipoTrabalho.objects.get(pk=cd['tipo'])
301 t.categoria = CategoriaTrabalho.objects.get_or_create(nome='Pendente')[0]
302 t.descricao_curta = cd['descricao_curta']
303 t.descricao_longa = cd['descricao_longa']
304 t.recursos = cd['recursos']
305 t.evento = Evento.objects.get(pk=1) # XXX: let the hammer play arround!
308 logged_in = request.user.palestrante_set.get()
309 t.palestrante.add(logged_in)
310 for i in cd.get('outros_palestrantes', []):
311 up = Palestrante.objects.get(pk=int(i))
312 t.palestrante.add(up)
315 c = {'form': form, 'ok': ok}
316 return build_response(request, 'inscrever_palestra.html', c)
320 @user_passes_test(lambda u:u.palestrante_set.count() == 1, login_url='/')
321 def meus_trabalhos(request):
323 p = Palestrante.objects.get(usuario=request.user)
324 except Palestrante.DoesNotExist:
326 c = {'palestrante': 0}
327 return build_response(request, 'meus_trabalhos.html', c)
328 t = Trabalho.objects.filter(palestrante=p)
329 c = {'trabalhos': t, 'palestrante': 1}
330 return build_response(request, 'meus_trabalhos.html', c)
332 <<<<<<< HEAD/views.py
334 @user_passes_test(lambda u:u.palestrante_set.count() == 1, login_url='/')
335 def editar_trabalho(request,codigo):
337 p = Palestrante.objects.get(usuario=request.user)
338 except Palestrante.DoesNotExist:
340 c = {'palestrante': 0}
341 return build_response(request, 'meus_trabalhos.html', c)
342 trabalho = get_object_or_404(Trabalho, id=codigo,palestrante=p)
343 Formulario = form_for_instance(trabalho)
344 if request.method == 'POST':
345 form = Formulario(request.POST)
348 t = Trabalho.objects.filter(palestrante=p)
349 c = {'trabalhos': t, 'palestrante': 1}
350 c['editado_sucesso']=trabalho.titulo
351 return build_response(request, 'meus_trabalhos.html', c)
355 c = {'formulario':form}
356 return build_response(request, 'editar_trabalho.html', c)
359 @user_passes_test(lambda u:u.palestrante_set.count() == 1, login_url='/')
360 def editar_trabalho(request,codigo):
362 p = Palestrante.objects.get(usuario=request.user)
363 except Palestrante.DoesNotExist:
365 c = {'palestrante': 0}
366 return build_response(request, 'meus_trabalhos.html', c)
367 trabalho = get_object_or_404(Trabalho, id=codigo,palestrante=p)
368 Formulario = form_for_instance(trabalho)
369 if request.method == 'POST':
370 form = Formulario(request.POST)
373 t = Trabalho.objects.filter(palestrante=p)
374 c = {'trabalhos': t, 'palestrante': 1}
375 c['editado_sucesso']=trabalho.titulo
376 return build_response(request, 'meus_trabalhos.html', c)
380 c = {'formulario':form}
381 return build_response(request, 'editar_trabalho.html', c)
384 @user_passes_test(lambda u:u.palestrante_set.count() == 1, login_url='/')
385 def editar_trabalho(request, codigo):
387 p = Palestrante.objects.get(usuario=request.user)
388 except Palestrante.DoesNotExist:
390 c = {'palestrante': 0}
391 return build_response(request, 'meus_trabalhos.html', c)
393 trabalho = get_object_or_404(Trabalho, id=codigo, palestrante=p)
394 Formulario = form_for_instance(trabalho)
396 form = Formulario(request.POST or None)
397 if request.POST and form.is_valid():
399 t = Trabalho.objects.filter(palestrante=p)
400 c = {'trabalhos': t, 'palestrante': 1}
401 c['editado_sucesso'] = trabalho.titulo
402 return build_response(request, 'meus_trabalhos.html', c)
404 c = {'formulario': form}
405 return build_response(request, 'editar_trabalho.html', c)
407 >>>>>>> 11faa820abeb69b688db5076aa4c1cc663dfeb53/views.py
410 def meus_dados(request):
412 entity = request.user.palestrante_set.get()
413 except Palestrante.DoesNotExist:
414 entity = request.user.participante_set.get()
416 FormKlass = form_for_instance(entity)
418 # ugly hammer to hide some fields...
419 del FormKlass.base_fields['usuario']
422 form = FormKlass(request.POST or None)
423 if request.POST and form.is_valid():
427 c = {'form': form, 'ok': ok, 'title': entity.__class__.__name__}
428 return build_response(request, 'editar_usuario.html', c)
432 def chamada_trabalhos(request):
433 return build_response(request, 'chamada_trabalhos.html')
436 def avaliacao(request):
437 return build_response(request, 'avaliacao.html')