[94b3e3f] | 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 | ) |
---|
[8fa24c3] | 6 | from multi_form_view import MultiModelFormView |
---|
[94b3e3f] | 7 | from django.views.generic import FormView |
---|
[bf47591] | 8 | |
---|
[8fa24c3] | 9 | from .forms import * |
---|
| 10 | from participantes.forms import ( |
---|
| 11 | FormsetParticipanteEvento |
---|
| 12 | ) |
---|
| 13 | |
---|
[94b3e3f] | 14 | class RegisterEvent(FormView): |
---|
[8fa24c3] | 15 | """! |
---|
| 16 | Muestra el formulario de registro de usuarios |
---|
| 17 | |
---|
| 18 | @author Ing. Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve) |
---|
| 19 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
| 20 | @date 20-11-2017 |
---|
| 21 | @version 1.0.0 |
---|
| 22 | """ |
---|
[94b3e3f] | 23 | |
---|
[8fa24c3] | 24 | template_name = "register.event.html" |
---|
[94b3e3f] | 25 | form_class = EventoForm |
---|
| 26 | form_participante = FormsetParticipanteEvento |
---|
| 27 | success_url = reverse_lazy('base:inicio') |
---|
| 28 | |
---|
| 29 | def get_context_data(self, **kwargs): |
---|
| 30 | context = super(RegisterEvent, self).get_context_data(**kwargs) |
---|
| 31 | if 'form' not in context: |
---|
| 32 | context['form'] = self.form_class() |
---|
| 33 | if 'form2' not in context: |
---|
| 34 | context['form2'] = self.form_participante |
---|
| 35 | return context |
---|
| 36 | |
---|
| 37 | def post(self, request, *args, **kwargs): |
---|
| 38 | nuevo_evento = self.form_class(request.POST).save(commit=False) |
---|
| 39 | nuevo_participante = self.form_participante(request.POST) |
---|
| 40 | consulta_api = 1 |
---|
| 41 | if self.form_class(request.POST).is_valid() and nuevo_participante.is_valid(): |
---|
| 42 | nuevo_evento.serial = consulta_api |
---|
| 43 | nuevo_evento.save() |
---|
| 44 | nuevo_participante.save() |
---|
| 45 | messages.success(self.request, "El usaurio %s, ha creado con exito,\ |
---|
| 46 | un nuevo envento %s" % |
---|
| 47 | (str(self.request.user), |
---|
| 48 | str(nuevo_evento))) |
---|
| 49 | else: |
---|
| 50 | messages.error(self.request, "Existe un error en el Formualario %s" % |
---|
| 51 | (str(self.form_class.errors, self.form_participante.errors))) |
---|
| 52 | return redirect(self.success_url) |
---|