1 | # -*- coding: utf-8 -*- |
---|
2 | """ |
---|
3 | Sistema Automatizado de Planificación Integral Comunal SAPIC |
---|
4 | |
---|
5 | Copyleft (@) 2017 CENDITEL nodo Mérida - Copyleft (@) 2017 CENDITEL nodo Mérida - https://planificacion.cenditel.gob.ve/trac/wiki/WikiStart#a5.-SistemaAutomatizadodePlanificaciónIntegralComunalSAPIC |
---|
6 | """ |
---|
7 | ## @package explicacion_situacional.views |
---|
8 | # |
---|
9 | # Vistas correspondientes a la explicacion situacional |
---|
10 | # @author Ing. Erwin Paredes (eparedes 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 | |
---|
16 | import time |
---|
17 | import datetime |
---|
18 | from django.contrib import messages |
---|
19 | from django.shortcuts import render, redirect |
---|
20 | from django.urls import reverse_lazy |
---|
21 | |
---|
22 | from explicacion_situacional.modelsEncuestas.modelsParticipacion import ( |
---|
23 | RespuestaSino, RespuestaOpciones, |
---|
24 | RespuestaAbierta, RespuestaUbicacion |
---|
25 | ) |
---|
26 | |
---|
27 | from django.views.generic import ( |
---|
28 | TemplateView, |
---|
29 | UpdateView |
---|
30 | ) |
---|
31 | from django.contrib import messages |
---|
32 | from utils.views import LoginRequeridoPerAuth |
---|
33 | |
---|
34 | from django.contrib.gis import forms |
---|
35 | |
---|
36 | from explicacion_situacional.modelsEncuestas.modelsConsultas import ( |
---|
37 | Consulta, |
---|
38 | Opcion, |
---|
39 | ) |
---|
40 | |
---|
41 | |
---|
42 | |
---|
43 | from .forms import ( |
---|
44 | RespuestaSinoForm, RespuestaAbiertaForm , |
---|
45 | RespuestaOpcionesForm |
---|
46 | ) |
---|
47 | |
---|
48 | |
---|
49 | class ModificarRespuestaView(LoginRequeridoPerAuth, TemplateView): |
---|
50 | """! |
---|
51 | Clase que mustra el template y gestiona la vista para modificar una respuesta en una encuesta |
---|
52 | |
---|
53 | @author Manuel Zambrano |
---|
54 | @copyright <a href='âhttp://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
55 | @date 30-08-2018 |
---|
56 | @version 1.0.0 |
---|
57 | """ |
---|
58 | |
---|
59 | template_name = 'modificar.respuesta.html' |
---|
60 | group_required = [u"Administradores", u"Voceros", u"Integrantes"] |
---|
61 | |
---|
62 | |
---|
63 | def get(self,*arg,**kwargs): |
---|
64 | """! |
---|
65 | Metodo que maneja las peticiones HTTP GET de la vista, Carga los valores iniciales al formulario |
---|
66 | |
---|
67 | @author Manuel Zambrano |
---|
68 | @copyright <a href='âhttp://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
69 | @date 30-08-2018 |
---|
70 | @param self <b>{object}</b> Objeto que instancia la clase |
---|
71 | @param kwargs <b>{object}</b> Objeto que contiene las variables de la url |
---|
72 | @param arg <b>{object}</b> |
---|
73 | @return retorna los datos de contexto |
---|
74 | """ |
---|
75 | |
---|
76 | if kwargs['tipo'] == '1' : |
---|
77 | respuesta = RespuestaOpciones.objects.select_related().get( |
---|
78 | pk = kwargs['pk'], |
---|
79 | user=self.request.user |
---|
80 | ) |
---|
81 | formulario = RespuestaOpcionesForm() |
---|
82 | formulario.fields['respuesta']._set_queryset(Opcion.objects.filter( |
---|
83 | pregunta=respuesta.opcion.pregunta |
---|
84 | )) |
---|
85 | formulario.fields['respuesta'].initial= respuesta.opcion |
---|
86 | |
---|
87 | |
---|
88 | if kwargs['tipo'] == '4' : #Hacer para cada tipo de respuesta8 |
---|
89 | respuesta = RespuestaSino.objects.select_related().get( |
---|
90 | pk = kwargs['pk'], |
---|
91 | user=self.request.user |
---|
92 | ) |
---|
93 | if respuesta.respuesta == True: |
---|
94 | formulario = RespuestaSinoForm(initial={ |
---|
95 | 'respuesta':respuesta.respuesta, |
---|
96 | }) |
---|
97 | else: |
---|
98 | justificacion = RespuestaAbierta.objects.select_related().get( |
---|
99 | user = self.request.user, |
---|
100 | pregunta = respuesta.pregunta |
---|
101 | ) |
---|
102 | formulario = RespuestaSinoForm(initial={ |
---|
103 | 'respuesta':respuesta.respuesta, |
---|
104 | 'justificacion':justificacion.texto_respuesta, |
---|
105 | }) |
---|
106 | |
---|
107 | if kwargs['tipo'] == '5' : |
---|
108 | respuesta = RespuestaAbierta.objects.select_related().get( |
---|
109 | pk = kwargs['pk'], |
---|
110 | user=self.request.user |
---|
111 | ) |
---|
112 | formulario = RespuestaAbiertaForm(initial={ |
---|
113 | 'respuesta':respuesta.texto_respuesta, |
---|
114 | }) |
---|
115 | |
---|
116 | kwargs['formulario'] = formulario |
---|
117 | kwargs['o'] = respuesta |
---|
118 | |
---|
119 | |
---|
120 | return super(ModificarRespuestaView,self).get(self,**kwargs) |
---|
121 | |
---|
122 | def post(self,*arg,**kwargs): |
---|
123 | """! |
---|
124 | Metodo que maneja las peticiones HTTP POST de la vista, Guarda la modificacion de la pregunta |
---|
125 | |
---|
126 | @author Manuel Zambrano |
---|
127 | @copyright <a href='âhttp://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
128 | @date 03-09-2018 |
---|
129 | @param self <b>{object}</b> Objeto que instancia la clase |
---|
130 | @param kwargs <b>{object}</b> Objeto que contiene las variables de la url |
---|
131 | @param arg <b>{object}</b> |
---|
132 | @return Redirecciona a la tabla de ecuestas |
---|
133 | """ |
---|
134 | |
---|
135 | if kwargs['tipo'] == '1' : |
---|
136 | respuesta = RespuestaOpciones.objects.select_related().get( |
---|
137 | pk = kwargs['pk'], |
---|
138 | user=self.request.user |
---|
139 | ) |
---|
140 | formulario = RespuestaOpcionesForm(self.request.POST,initial={ |
---|
141 | 'respuesta':respuesta.opcion, |
---|
142 | }) |
---|
143 | if formulario.is_valid() and formulario.has_changed(): |
---|
144 | opcion = formulario.cleaned_data['respuesta'] |
---|
145 | respuesta.opcion = opcion |
---|
146 | respuesta.save() |
---|
147 | |
---|
148 | if kwargs['tipo'] == '5': |
---|
149 | respuesta = RespuestaAbierta.objects.select_related().get( |
---|
150 | pk = kwargs['pk'], |
---|
151 | user=self.request.user |
---|
152 | ) |
---|
153 | formulario = RespuestaAbiertaForm(self.request.POST, initial={ |
---|
154 | 'respuesta':respuesta.texto_respuesta, |
---|
155 | }) |
---|
156 | if formulario.is_valid() and formulario.has_changed(): |
---|
157 | texto_respuesta = formulario.cleaned_data['respuesta'] |
---|
158 | respuesta.texto_respuesta = texto_respuesta |
---|
159 | respuesta.save() |
---|
160 | |
---|
161 | if kwargs['tipo'] == '4': |
---|
162 | respuesta = RespuestaSino.objects.select_related().get( |
---|
163 | pk = kwargs['pk'], |
---|
164 | user = self.request.user |
---|
165 | ) |
---|
166 | formulario = RespuestaSinoForm(self.request.POST) |
---|
167 | if formulario.is_valid(): |
---|
168 | if formulario.cleaned_data['respuesta'] : |
---|
169 | respuesta.respuesta = formulario.cleaned_data['respuesta'] |
---|
170 | respuesta.save() |
---|
171 | else: |
---|
172 | try: |
---|
173 | justificacion = RespuestaAbierta.objects.select_related().get( |
---|
174 | user = self.request.user, |
---|
175 | pregunta = respuesta.pregunta |
---|
176 | ) |
---|
177 | texto_respuesta = formulario.cleaned_data['justificacion'] |
---|
178 | justificacion.texto_respuesta = texto_respuesta |
---|
179 | justificacion.es_justificacion = True |
---|
180 | respuesta.respuesta = formulario.cleaned_data['respuesta'] |
---|
181 | respuesta.save() |
---|
182 | justificacion.save() |
---|
183 | except: |
---|
184 | justificacion = RespuestaAbierta() |
---|
185 | justificacion.pregunta = respuesta.pregunta |
---|
186 | justificacion.texto_respuesta = formulario.cleaned_data['justificacion'] |
---|
187 | justificacion.user = self.request.user |
---|
188 | justificacion.es_justificacion = True |
---|
189 | justificacion.save() |
---|
190 | respuesta.respuesta = formulario.cleaned_data['respuesta'] |
---|
191 | respuesta.save() |
---|
192 | else : |
---|
193 | messages.error(self.request, 'Error el formulario \ |
---|
194 | No es Valido') #provicional, mientras se valida el formulario con js |
---|
195 | return redirect(self.request.META.get("HTTP_REFERER")) |
---|
196 | |
---|