[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 | |
---|
[a1de3f1] | 45 | @method_decorator(csrf_exempt, name='dispatch') |
---|
[d60a9ab] | 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) |
---|
[a1de3f1] | 72 | pasaporte = request.POST.get('pasaporte', None) |
---|
[d17da63] | 73 | pasaporte = request.POST.get('pasaporte', None) |
---|
[d60a9ab] | 74 | if evento_id is not None and pasaporte is not None: |
---|
| 75 | if serial is not None: |
---|
[b48da64] | 76 | try: |
---|
[a1de3f1] | 77 | update_evento = self.model.objects.get(pk=evento_id) |
---|
[b48da64] | 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: |
---|
[a1de3f1] | 86 | participante = Participante.objects.get(pasaporte=pasaporte) |
---|
[b48da64] | 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: |
---|
[a1de3f1] | 93 | update_parti_event = self.model_participante.objects.get( |
---|
[b48da64] | 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 | |
---|
[d60a9ab] | 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) |
---|