1 | from django.shortcuts import render |
---|
2 | from django.http import JsonResponse |
---|
3 | from django.views import View |
---|
4 | |
---|
5 | from .models import ( |
---|
6 | ParticipanteEvento |
---|
7 | ) |
---|
8 | from eventos.models import ( |
---|
9 | Evento |
---|
10 | ) |
---|
11 | |
---|
12 | class ParticipanteEventoSearch(View): |
---|
13 | """! |
---|
14 | Muestra si un participante esta registrado en un evento |
---|
15 | |
---|
16 | @author Rodrigo Boet (rboet at cenditel.gob.ve) |
---|
17 | @copyright <a href='https://www.gnu.org/licenses/gpl-3.0.en.html'>GNU Public License versión 3 (GPLv3)</a> |
---|
18 | @date 20-11-2017 |
---|
19 | @version 1.0.0 |
---|
20 | """ |
---|
21 | |
---|
22 | def get(self,request,pk,pasaporte): |
---|
23 | """! |
---|
24 | Metodo para antender la vista por GET |
---|
25 | |
---|
26 | @author Rodrigo Boet (rboet at cenditel.gob.ve) |
---|
27 | @copyright GNU/GPLv3 |
---|
28 | @date 20-11-2017 |
---|
29 | @param self <b>{object}</b> Objeto que instancia la clase |
---|
30 | @param request <b>{object}</b> Objeto que contiene la petición |
---|
31 | @param pk <b>{int}</b> Recibe el id del evento |
---|
32 | @param pasaporte <b>{str}</b> Recibe el número de pasaporte |
---|
33 | @return Retorna un Json con la respuesta |
---|
34 | """ |
---|
35 | participante = ParticipanteEvento.objects.filter(fk_evento=pk,fk_participante__pasaporte=pasaporte) |
---|
36 | data = {} |
---|
37 | if(participante): |
---|
38 | p = participante.get() |
---|
39 | data = {'firmo':p.firma,'datos':{'nombres':p.fk_participante.nombres,'apellidos':p.fk_participante.apellidos, |
---|
40 | 'pasaporte':pasaporte,'correo':p.fk_participante.correo}} |
---|
41 | return JsonResponse(data,safe=False) |
---|
42 | |
---|
43 | |
---|
44 | class AjaxParticipanteFirmaEvento(View): |
---|
45 | """! |
---|
46 | Ajax para sincronizar la firma del participante |
---|
47 | |
---|
48 | @author Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve) |
---|
49 | @copyright <a href='https://www.gnu.org/licenses/gpl-3.0.en.html'>GNU Public License versión 3 (GPLv3)</a> |
---|
50 | @date 21-11-2017 |
---|
51 | @version 1.0.0 |
---|
52 | """ |
---|
53 | model = Evento |
---|
54 | model_participante = ParticipanteEvento |
---|
55 | |
---|
56 | def post(self, request): |
---|
57 | """! |
---|
58 | Metodo para antender la vista por POST |
---|
59 | |
---|
60 | @author Leonel P. Hernandez M (lhernandez at cenditel.gob.ve) |
---|
61 | @copyright GNU/GPLv3 |
---|
62 | @date 21-11-2017 |
---|
63 | @return Retorna un Json con la respuesta |
---|
64 | """ |
---|
65 | data = {} |
---|
66 | validate = False |
---|
67 | mensaje = '' |
---|
68 | evento_id = request.POST.get('event_id', None) |
---|
69 | serial = request.POST.get('serial', None) |
---|
70 | pasaporte = request.POST.get('pasoporte', None) |
---|
71 | if evento_id is not None and pasaporte is not None: |
---|
72 | if serial is not None: |
---|
73 | update_evento = self.model.object.get(pk=evento_id) |
---|
74 | update_evento.serial = serial |
---|
75 | update_evento.save() |
---|
76 | mensaje += 'Se actualizo el serial del evento \n' |
---|
77 | update_parti_event = self.model_participante.object.get( |
---|
78 | pasaporte=pasaporte) |
---|
79 | update_parti_event.firma = True |
---|
80 | update_parti_event.save() |
---|
81 | mensaje += 'Se actualizo la firma del participante %s, \ |
---|
82 | para el evento %s' % (update_parti_event.fk_participante.nombres, |
---|
83 | update_parti_event.fk_evento.nombre_evento) |
---|
84 | validate = True |
---|
85 | else: |
---|
86 | mensaje += 'Debes enviar al menos\ |
---|
87 | dos argumentos (evento_id, pasaporte)' |
---|
88 | validate = False |
---|
89 | data = {'validate': validate, 'mensaje': mensaje} |
---|
90 | |
---|
91 | return JsonResponse(data, safe=False) |
---|