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, Participante |
---|
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,'documento':p.fk_evento.serial}} |
---|
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 | try: |
---|
74 | update_evento = self.model.object.get(pk=evento_id) |
---|
75 | update_evento.serial = serial |
---|
76 | update_evento.save() |
---|
77 | mensaje += 'Se actualizo el serial del evento \n' |
---|
78 | except Exception as e: |
---|
79 | print (e) |
---|
80 | validate = False |
---|
81 | mensaje += 'No existe el evento que desea actualizar \n' |
---|
82 | try: |
---|
83 | participante = Participante.object.get(pasaporte=pasaporte) |
---|
84 | except Exception as e: |
---|
85 | print (e) |
---|
86 | validate = False |
---|
87 | mensaje += 'El pasaporte no coincide con los\ |
---|
88 | participantes que se ecuentran registrados \n' |
---|
89 | try: |
---|
90 | update_parti_event = self.model_participante.object.get( |
---|
91 | fk_participante=participante.pk, |
---|
92 | fk_evento=evento_id) |
---|
93 | update_parti_event.firma = True |
---|
94 | update_parti_event.save() |
---|
95 | mensaje += 'Se actualizo la firma del participante %s, \ |
---|
96 | para el evento %s' % (update_parti_event.fk_participante.nombres, |
---|
97 | update_parti_event.fk_evento.nombre_evento) |
---|
98 | validate = True |
---|
99 | except Exception as e: |
---|
100 | print(e) |
---|
101 | validate = False |
---|
102 | mensaje += 'El evento no esta asociado al participante\ |
---|
103 | o no se encuentra registrado\n' |
---|
104 | |
---|
105 | else: |
---|
106 | mensaje += 'Debes enviar al menos\ |
---|
107 | dos argumentos (evento_id, pasaporte)' |
---|
108 | validate = False |
---|
109 | data = {'validate': validate, 'mensaje': mensaje} |
---|
110 | |
---|
111 | return JsonResponse(data, safe=False) |
---|