1 | from django.contrib import messages |
---|
2 | from django.core.urlresolvers import reverse_lazy |
---|
3 | from django.shortcuts import ( |
---|
4 | render, redirect, get_object_or_404 |
---|
5 | ) |
---|
6 | from django.views.generic import ListView, FormView |
---|
7 | |
---|
8 | from multi_form_view import MultiModelFormView |
---|
9 | |
---|
10 | from .forms import * |
---|
11 | from participantes.forms import ( |
---|
12 | FormsetParticipanteEvento |
---|
13 | ) |
---|
14 | from .models import Evento |
---|
15 | |
---|
16 | |
---|
17 | class RegisterEvent(FormView): |
---|
18 | """! |
---|
19 | Muestra el formulario de registro de usuarios |
---|
20 | |
---|
21 | @author Ing. Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve) |
---|
22 | @copyright <a href='https://www.gnu.org/licenses/gpl-3.0.en.html'>GNU Public License versión 3 (GPLv3)</a> |
---|
23 | @date 20-11-2017 |
---|
24 | @version 1.0.0 |
---|
25 | """ |
---|
26 | |
---|
27 | template_name = "register.event.html" |
---|
28 | form_class = EventoForm |
---|
29 | form_participante = FormsetParticipanteEvento |
---|
30 | success_url = reverse_lazy('base:inicio') |
---|
31 | |
---|
32 | def get_context_data(self, **kwargs): |
---|
33 | context = super(RegisterEvent, self).get_context_data(**kwargs) |
---|
34 | if 'form' not in context: |
---|
35 | context['form'] = self.form_class() |
---|
36 | if 'form2' not in context: |
---|
37 | context['form2'] = self.form_participante |
---|
38 | return context |
---|
39 | |
---|
40 | def post(self, request, *args, **kwargs): |
---|
41 | nuevo_evento = self.form_class(request.POST).save(commit=False) |
---|
42 | nuevo_participante = self.form_participante(request.POST) |
---|
43 | consulta_api = 1 |
---|
44 | if self.form_class(request.POST).is_valid() and nuevo_participante.is_valid(): |
---|
45 | nuevo_evento.serial = consulta_api |
---|
46 | nuevo_evento.save() |
---|
47 | nuevo_participante.save() |
---|
48 | messages.success(self.request, "El usaurio %s, ha creado con exito,\ |
---|
49 | un nuevo envento %s" % |
---|
50 | (str(self.request.user), |
---|
51 | str(nuevo_evento))) |
---|
52 | else: |
---|
53 | messages.error(self.request, "Existe un error en el Formualario %s" % |
---|
54 | (str(self.form_class.errors, self.form_participante.errors))) |
---|
55 | return redirect(self.success_url) |
---|
56 | |
---|
57 | |
---|
58 | class ListEvent(ListView): |
---|
59 | """! |
---|
60 | Muestra el listado de eventos |
---|
61 | |
---|
62 | @author Rodrigo Boet (rboet at cenditel.gob.ve) |
---|
63 | @copyright <a href='https://www.gnu.org/licenses/gpl-3.0.en.html'>GNU Public License versión 3 (GPLv3)</a> |
---|
64 | @date 20-11-2017 |
---|
65 | @version 1.0.0 |
---|
66 | """ |
---|
67 | model = Evento |
---|
68 | template_name = "evento.list.html" |
---|
69 | paginate_by = 5 |
---|
70 | |
---|
71 | class SignEvent(FormView): |
---|
72 | """! |
---|
73 | Muestra el formulario para buscar y luego firmar documento |
---|
74 | |
---|
75 | @author Rodrigo Boet (rboet at cenditel.gob.ve) |
---|
76 | @copyright <a href='https://www.gnu.org/licenses/gpl-3.0.en.html'>GNU Public License versión 3 (GPLv3)</a> |
---|
77 | @date 20-11-2017 |
---|
78 | @version 1.0.0 |
---|
79 | """ |
---|
80 | form_class = FirmaEventoForm |
---|
81 | template_name = "evento.firma.html" |
---|
82 | |
---|
83 | def get_context_data(self, **kwargs): |
---|
84 | """! |
---|
85 | Metodo que permite cargar de nuevo valores en los datos de contexto de la vista |
---|
86 | |
---|
87 | @author Rodrigo Boet (rboet at cenditel.gob.ve) |
---|
88 | @copyright GNU/GPLv3 |
---|
89 | @date 20-11-2017 |
---|
90 | @param self <b>{object}</b> Objeto que instancia la clase |
---|
91 | @param kwargs <b>{object}</b> Objeto que contiene los datos de contexto |
---|
92 | @return Retorna los datos de contexto |
---|
93 | """ |
---|
94 | kwargs['nombre_evento'] = Evento.objects.get(pk=int(self.kwargs['pk'])) |
---|
95 | return super(SignEvent, self).get_context_data(**kwargs) |
---|