1 | from django.shortcuts import render |
---|
2 | from django.http import JsonResponse |
---|
3 | from django.views import View |
---|
4 | from django.utils.decorators import method_decorator |
---|
5 | from django.views.decorators.csrf import csrf_exempt |
---|
6 | |
---|
7 | from .models import ( |
---|
8 | ParticipanteEvento, Participante |
---|
9 | ) |
---|
10 | from eventos.models import ( |
---|
11 | Evento |
---|
12 | ) |
---|
13 | |
---|
14 | class ParticipanteEventoSearch(View): |
---|
15 | """! |
---|
16 | Muestra si un participante esta registrado en un evento |
---|
17 | |
---|
18 | @author Rodrigo Boet (rboet at cenditel.gob.ve) |
---|
19 | @copyright <a href='https://www.gnu.org/licenses/gpl-3.0.en.html'>GNU Public License versión 3 (GPLv3)</a> |
---|
20 | @date 20-11-2017 |
---|
21 | @version 1.0.0 |
---|
22 | """ |
---|
23 | |
---|
24 | def get(self,request,pk,pasaporte): |
---|
25 | """! |
---|
26 | Metodo para antender la vista por GET |
---|
27 | |
---|
28 | @author Rodrigo Boet (rboet at cenditel.gob.ve) |
---|
29 | @copyright GNU/GPLv3 |
---|
30 | @date 20-11-2017 |
---|
31 | @param self <b>{object}</b> Objeto que instancia la clase |
---|
32 | @param request <b>{object}</b> Objeto que contiene la petición |
---|
33 | @param pk <b>{int}</b> Recibe el id del evento |
---|
34 | @param pasaporte <b>{str}</b> Recibe el número de pasaporte |
---|
35 | @return Retorna un Json con la respuesta |
---|
36 | """ |
---|
37 | participante = ParticipanteEvento.objects.filter(fk_evento=pk,fk_participante__pasaporte=pasaporte) |
---|
38 | data = {} |
---|
39 | if(participante): |
---|
40 | p = participante.get() |
---|
41 | data = {'firmo':p.firma,'datos':{'nombres':p.fk_participante.nombres,'apellidos':p.fk_participante.apellidos, |
---|
42 | 'pasaporte':pasaporte,'correo':p.fk_participante.correo,'documento':p.fk_evento.serial}} |
---|
43 | return JsonResponse(data,safe=False) |
---|
44 | |
---|
45 | @method_decorator(csrf_exempt, name='dispatch') |
---|
46 | class AjaxParticipanteFirmaEvento(View): |
---|
47 | """! |
---|
48 | Ajax para sincronizar la firma del participante |
---|
49 | |
---|
50 | @author Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve) |
---|
51 | @copyright <a href='https://www.gnu.org/licenses/gpl-3.0.en.html'>GNU Public License versión 3 (GPLv3)</a> |
---|
52 | @date 21-11-2017 |
---|
53 | @version 1.0.0 |
---|
54 | """ |
---|
55 | model = Evento |
---|
56 | model_participante = ParticipanteEvento |
---|
57 | |
---|
58 | def post(self, request): |
---|
59 | """! |
---|
60 | Metodo para antender la vista por POST |
---|
61 | |
---|
62 | @author Leonel P. Hernandez M (lhernandez at cenditel.gob.ve) |
---|
63 | @copyright GNU/GPLv3 |
---|
64 | @date 21-11-2017 |
---|
65 | @return Retorna un Json con la respuesta |
---|
66 | """ |
---|
67 | data = {} |
---|
68 | validate = False |
---|
69 | mensaje = '' |
---|
70 | evento_id = request.POST.get('event_id', None) |
---|
71 | serial = request.POST.get('serial', None) |
---|
72 | pasaporte = request.POST.get('pasaporte', None) |
---|
73 | pasaporte = request.POST.get('pasaporte', None) |
---|
74 | if evento_id is not None and pasaporte is not None: |
---|
75 | if serial is not None: |
---|
76 | try: |
---|
77 | update_evento = self.model.objects.get(pk=evento_id) |
---|
78 | update_evento.serial = serial |
---|
79 | update_evento.save() |
---|
80 | mensaje += 'Se actualizo el serial del evento \n' |
---|
81 | except Exception as e: |
---|
82 | print (e) |
---|
83 | validate = False |
---|
84 | mensaje += 'No existe el evento que desea actualizar \n' |
---|
85 | try: |
---|
86 | participante = Participante.objects.get(pasaporte=pasaporte) |
---|
87 | except Exception as e: |
---|
88 | print (e) |
---|
89 | validate = False |
---|
90 | mensaje += 'El pasaporte no coincide con los\ |
---|
91 | participantes que se ecuentran registrados \n' |
---|
92 | try: |
---|
93 | update_parti_event = self.model_participante.objects.get( |
---|
94 | fk_participante=participante.pk, |
---|
95 | fk_evento=evento_id) |
---|
96 | update_parti_event.firma = True |
---|
97 | update_parti_event.save() |
---|
98 | mensaje += 'Se actualizo la firma del participante %s, \ |
---|
99 | para el evento %s' % (update_parti_event.fk_participante.nombres, |
---|
100 | update_parti_event.fk_evento.nombre_evento) |
---|
101 | validate = True |
---|
102 | except Exception as e: |
---|
103 | print(e) |
---|
104 | validate = False |
---|
105 | mensaje += 'El evento no esta asociado al participante\ |
---|
106 | o no se encuentra registrado\n' |
---|
107 | |
---|
108 | else: |
---|
109 | mensaje += 'Debes enviar al menos\ |
---|
110 | dos argumentos (evento_id, pasaporte)' |
---|
111 | validate = False |
---|
112 | data = {'validate': validate, 'mensaje': mensaje} |
---|
113 | |
---|
114 | return JsonResponse(data, safe=False) |
---|
115 | |
---|
116 | class ParticipantesRestantes(View): |
---|
117 | """! |
---|
118 | Muestra si el participante restante es el último |
---|
119 | |
---|
120 | @author Rodrigo Boet (rboet at cenditel.gob.ve) |
---|
121 | @copyright <a href='https://www.gnu.org/licenses/gpl-3.0.en.html'>GNU Public License versión 3 (GPLv3)</a> |
---|
122 | @date 22-11-2017 |
---|
123 | @version 1.0.0 |
---|
124 | """ |
---|
125 | |
---|
126 | def get(self,request,evento): |
---|
127 | """! |
---|
128 | Metodo para antender la vista por GET |
---|
129 | |
---|
130 | @author Rodrigo Boet (rboet at cenditel.gob.ve) |
---|
131 | @copyright GNU/GPLv3 |
---|
132 | @date 22-11-2017 |
---|
133 | @param self <b>{object}</b> Objeto que instancia la clase |
---|
134 | @param request <b>{object}</b> Objeto que contiene la petición |
---|
135 | @param evento <b>{int}</b> Recibe el id del evento |
---|
136 | @return Retorna un Json con la respuesta |
---|
137 | """ |
---|
138 | participante_evento = ParticipanteEvento.objects.select_related().filter(fk_evento=evento) |
---|
139 | falta_porfirma = participante_evento.filter(firma=False).count() |
---|
140 | data = {} |
---|
141 | if(falta_porfirma==1): |
---|
142 | evento = Evento.objects.get(pk=evento) |
---|
143 | data = {'valid':True,'data':{'posX':evento.pos_x,'posY':evento.pos_y,'page':evento.pag}} |
---|
144 | else: |
---|
145 | data = {'valid':False} |
---|
146 | |
---|
147 | return JsonResponse(data, safe=False) |
---|