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