1 | # -*- coding: utf-8 -*- |
---|
2 | """ |
---|
3 | Sistema de Consulta Pública |
---|
4 | |
---|
5 | Copyleft (@) 2017 CENDITEL nodo Mérida - https://planificacion.cenditel.gob.ve/trac/wiki/ModeladoTopicos_2017 |
---|
6 | """ |
---|
7 | ## @package participacion.views |
---|
8 | # |
---|
9 | # Vistas correspondientes a la aplicación participacion |
---|
10 | # @author Rodrigo Boet (rboet at cenditel.gob.ve) |
---|
11 | # @author <a href='http://www.cenditel.gob.ve'>Centro Nacional de Desarrollo e Investigación en TecnologÃas Libres |
---|
12 | # (CENDITEL) nodo Mérida - Venezuela</a> |
---|
13 | # @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
14 | # @version 1.0 |
---|
15 | from django.shortcuts import render, redirect |
---|
16 | from django.core.urlresolvers import reverse_lazy |
---|
17 | from django.views.generic import FormView, TemplateView |
---|
18 | from .forms import ParticipacionSelectForm, ParticipacionSearchForm, ParticipacionEntesAdscritosForm |
---|
19 | from base.functions import cargar_entes |
---|
20 | from consulta.models import Pregunta, Opcion |
---|
21 | import requests |
---|
22 | import json |
---|
23 | |
---|
24 | class ParticipacionIndex(FormView): |
---|
25 | """! |
---|
26 | Clase que gestiona la vista principal de la participación |
---|
27 | |
---|
28 | @author Rodrigo Boet (rboet at cenditel.gob.ve) |
---|
29 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
30 | @date 22-02-2017 |
---|
31 | @version 1.0.0 |
---|
32 | """ |
---|
33 | template_name = "participacion.index.html" |
---|
34 | form_class = ParticipacionSelectForm |
---|
35 | |
---|
36 | def get_success_url(self): |
---|
37 | """! |
---|
38 | Metodo que permite definir la url de dirección al ser válido el formulario |
---|
39 | |
---|
40 | @author Rodrigo Boet (rboet at cenditel.gob.ve) |
---|
41 | @copyright GNU/GPLv2 |
---|
42 | @date 22-02-2017 |
---|
43 | @param self <b>{object}</b> Objeto que instancia la clase |
---|
44 | @return Retorna la url |
---|
45 | """ |
---|
46 | consulta = self.request.POST['consultas'] |
---|
47 | return reverse_lazy('participacion_busqueda', |
---|
48 | kwargs={'pk': consulta}) |
---|
49 | |
---|
50 | |
---|
51 | class ParticipacionSearch(FormView): |
---|
52 | """! |
---|
53 | Clase que gestiona la busqueda para la participación |
---|
54 | |
---|
55 | @author Rodrigo Boet (rboet at cenditel.gob.ve) |
---|
56 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
57 | @date 23-02-2017 |
---|
58 | @version 1.0.0 |
---|
59 | """ |
---|
60 | template_name = "participacion.search.html" |
---|
61 | form_class = ParticipacionSearchForm |
---|
62 | |
---|
63 | def get_success_url(self): |
---|
64 | """! |
---|
65 | Metodo que permite definir la url de dirección al ser válido el formulario |
---|
66 | |
---|
67 | @author Rodrigo Boet (rboet at cenditel.gob.ve) |
---|
68 | @copyright GNU/GPLv2 |
---|
69 | @date 23-02-2017 |
---|
70 | @param self <b>{object}</b> Objeto que instancia la clase |
---|
71 | @return Retorna la url |
---|
72 | """ |
---|
73 | #consulta = self.request.POST['consultas'] |
---|
74 | print self.kwargs['pk'] |
---|
75 | return reverse_lazy('participacion_consulta', |
---|
76 | kwargs={'pk': self.kwargs['pk']}) |
---|
77 | |
---|
78 | class ParticipacionCreate(TemplateView): |
---|
79 | """! |
---|
80 | Clase que gestiona la vista principal de la participación |
---|
81 | |
---|
82 | @author Rodrigo Boet (rboet at cenditel.gob.ve) |
---|
83 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
84 | @date 22-02-2017 |
---|
85 | @version 1.0.0 |
---|
86 | """ |
---|
87 | template_name = "participacion.create.html" |
---|
88 | |
---|
89 | def get_context_data(self, **kwargs): |
---|
90 | """! |
---|
91 | Metodo que permite cargar de nuevo valores en los datos de contexto de la vista |
---|
92 | |
---|
93 | @author Rodrigo Boet (rboet at cenditel.gob.ve) |
---|
94 | @copyright GNU/GPLv2 |
---|
95 | @date 23-02-2017 |
---|
96 | @param self <b>{object}</b> Objeto que instancia la clase |
---|
97 | @param kwargs <b>{object}</b> Objeto que contiene los datos de contexto |
---|
98 | @return Retorna los datos de contexto |
---|
99 | """ |
---|
100 | valores = {} |
---|
101 | for pregunta in Pregunta.objects.filter(consulta_id=kwargs['pk']).all(): |
---|
102 | label = '<label>'+pregunta.texto_pregunta+'</label>' |
---|
103 | campo = '' |
---|
104 | if pregunta.tipo_pregunta.id == 1: |
---|
105 | campo = '' |
---|
106 | for opcion in Opcion.objects.filter(pregunta_id=pregunta.id).all(): |
---|
107 | campo += '<label for="'+kwargs['pk']+'">'+opcion.texto_opcion+'</label><input type="radio" name="consulta_respuesta_radio_'+kwargs['pk']+'" id="'+kwargs['pk']+'"value="'+str(opcion.id)+'" class="icheck">' |
---|
108 | elif pregunta.tipo_pregunta.id == 2: |
---|
109 | campo = '' |
---|
110 | for opcion in Opcion.objects.filter(pregunta_id=pregunta.id).all(): |
---|
111 | campo += '<label for="'+kwargs['pk']+'">'+opcion.texto_opcion+'</label><input type="checkbox" name="consulta_respuesta_check_'+kwargs['pk']+'" id="'+kwargs['pk']+'"value="'+str(opcion.id)+'" class="icheck">' |
---|
112 | elif pregunta.tipo_pregunta.id > 2 and pregunta.tipo_pregunta.id < 5: |
---|
113 | campo += '<label for="'+kwargs['pk']+'">Si</label><input type="radio" name="consulta_respuesta_sino_'+kwargs['pk']+'" id="'+kwargs['pk']+'"value="Si" class="icheck">' |
---|
114 | if(pregunta.tipo_pregunta.id == 3): |
---|
115 | campo += '<label for="'+kwargs['pk']+'">No</label><input type="radio" name="consulta_respuesta_sino_'+kwargs['pk']+'" id="'+kwargs['pk']+'"value="No" class="icheck">' |
---|
116 | else: |
---|
117 | campo += '<label for="'+kwargs['pk']+'">No</label><input type="radio" name="consulta_respuesta_sino_'+kwargs['pk']+'" id="'+kwargs['pk']+'"value="No" class="icheck need_justification">' |
---|
118 | campo += '<div id="div_justificar_'+kwargs['pk']+'" style="display:none;"><label>Justifique su Respuesta</label>' |
---|
119 | campo += '<textarea class="form-control" id="respuesta_justificar_'+kwargs['pk']+'" name="consulta_respuesta_justificar_'+kwargs['pk']+'">' |
---|
120 | campo += '</textarea></div>' |
---|
121 | else: |
---|
122 | campo = '<textarea class="form-control" name="consulta_respuesta_abierta_'+kwargs['pk']+'"></textarea>' |
---|
123 | valores[pregunta.id] = {'label':label,'field':campo} |
---|
124 | kwargs['preguntas'] = valores |
---|
125 | return super(ParticipacionCreate, self).get_context_data(**kwargs) |
---|
126 | |
---|
127 | def post(self,request,pk): |
---|
128 | """! |
---|
129 | Metodo que sobreescribe el post del formulario |
---|
130 | |
---|
131 | @author Rodrigo Boet (rboet at cenditel.gob.ve) |
---|
132 | @copyright GNU/GPLv2 |
---|
133 | @date 20-03-2017 |
---|
134 | @param self <b>{object}</b> Objeto que instancia la clase |
---|
135 | @param request <b>{object}</b> Objeto que instancia la petición |
---|
136 | @param pk <b>{int}</b> Recibe el id de la consulta |
---|
137 | @return Retorna los datos de contexto |
---|
138 | """ |
---|
139 | print request.POST |
---|
140 | return redirect(reverse_lazy('participacion_consulta',kwargs={'pk':pk})) |
---|
141 | |
---|
142 | |
---|
143 | class ParticipacionEntesAdscritos(TemplateView): |
---|
144 | template_name = "participacion.entes.html" |
---|
145 | form_class = ParticipacionEntesAdscritosForm |
---|
146 | |
---|
147 | def get(self,request,pk): |
---|
148 | #data = cargar_entes() |
---|
149 | #print data |
---|
150 | #jsonn = {'x': "xxxx", 'y': "yyyy"} |
---|
151 | #a = 'http://192.168.12.152:8080/services_sipes/entes_planificadores/views/servicios_webs?display_id=page_2&parent=1405.json' |
---|
152 | #data2 = requests.get('http://192.168.12.82/proyectos/usuarios.json').json() |
---|
153 | #print data |
---|
154 | #data = json.loads(jsonn.read()) |
---|
155 | #return render(request,self.template_name, {'data':data}) |
---|
156 | #url = 'http://192.168.12.82/proyectos/usuarios.json' |
---|
157 | #url = 'http://192.168.12.152:8080/services_sipes/entes_planificadores/views/servicios_webs?display_id=page_2&parent=1405' |
---|
158 | url = "http://192.168.12.152:8080/services_sipes/entes_planificadores/views/servicios_webs?display_id=page_2" |
---|
159 | |
---|
160 | r = requests.get(url) |
---|
161 | if not r.status_code == 200: |
---|
162 | print "ERROR:" |
---|
163 | return ('', 'ocurrio error...'), |
---|
164 | data = r.json() |
---|
165 | print "+++++++++++++++++++++++++++++++++++" |
---|
166 | print data |
---|
167 | print "+++++++++++++++++++++++++++++++++++" |
---|
168 | return render(request,self.template_name, {'data':data, 'pk':pk}) |
---|