Conjunto de cambios 810b149 en participacion_consulta para participacion
- Fecha y hora:
- 28/09/2017 15:52:38 (hace 7 años)
- Branches:
- master
- Children:
- fd72443
- Parents:
- 935ded3
- Ubicación:
- participacion
- Ficheros:
-
- 1 añadido
- 1 borrado
- 4 editados
Leyenda
- No modificado
- Añadido
- Eliminado
-
participacion/templates/participacion.create.html
rd923030 r810b149 18 18 <div class="swiper-slide"> 19 19 <div class="center"> 20 <a type="button" class="btn submit " onclick="send_poll();">Enviar</a>20 <a type="button" class="btn submit waves-effect blue lighten-1" onclick="send_poll();">Enviar</a> 21 21 </div> 22 22 </div> … … 27 27 <div class="swiper-button-prev"></div> 28 28 </div> 29 <a type="button" class="btn " href="{% url 'participacion_index' %}">Regresar</a>29 <a type="button" class="btn waves-effect blue lighten-1" href="{% url 'participacion_index' %}">Regresar</a> 30 30 </form> 31 31 -
participacion/templates/participacion.index.html
rc1ce0dd r810b149 15 15 </ol> 16 16 <div class="card-action"> 17 <a type="button" class="btn waves-effect " href="{% url 'participacion_create' item.id %}">17 <a type="button" class="btn waves-effect blue lighten-1" href="{% url 'participacion_create' item.id %}"> 18 18 <i class="material-icons left">insert_chart</i> Participar 19 19 </a> … … 21 21 </div> 22 22 {% endfor %} 23 {% if consultas %} 24 {% include 'base.paginator.html' with paginator=page_obj %} 25 {% endif %} 23 26 24 27 </div> -
participacion/urls.py
rd923030 r810b149 20 20 url(r'^crear/(?P<pk>\d+)$', ParticipacionCreate.as_view(), name = "participacion_create"), 21 21 url(r'^crear/$', ParticipacionCreate.as_view(), name = "participacion_create_nid"), 22 url(r'^mi-participacion$', MiParticipacion.as_view(), name = "mi_participacion"), 22 23 ] 23 24 -
participacion/views.py
rd923030 r810b149 21 21 from django.contrib.auth.models import User 22 22 from django.contrib.auth.mixins import LoginRequiredMixin 23 from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger 23 24 from base.functions import cargar_consultas, cargar_consulta_id, validar_participacion_general 24 25 from .models import RespuestaAbierta, RespuestaOpciones, RespuestaSino … … 35 36 """ 36 37 template_name = "participacion.index.html" 38 paginate_by = 5 37 39 38 40 def get_context_data(self, **kwargs): … … 48 50 """ 49 51 kwargs['consultas'] = cargar_consultas() 52 paginator = Paginator(kwargs['consultas'], self.paginate_by) 53 page = self.request.GET.get('page') 54 try: 55 kwargs['page_obj'] = paginator.page(page) 56 kwargs['consultas'] = kwargs['page_obj'].object_list 57 except PageNotAnInteger: 58 kwargs['page_obj'] = paginator.page(1) 59 kwargs['consultas'] = kwargs['page_obj'].object_list 60 except EmptyPage: 61 kwargs['page_obj'] = paginator.page(paginator.num_pages) 62 kwargs['consultas'] = kwargs['page_obj'].object_list 50 63 return super(ParticipacionIndex, self).get_context_data(**kwargs) 51 64 … … 253 266 254 267 255 256 class ParticipacionSimpleCreate(LoginRequiredMixin,TemplateView): 268 class MiParticipacion(LoginRequiredMixin,TemplateView): 257 269 """! 258 Clase que gestiona la vista principal de la participación simple270 Clase para mostrar los resultados en las consultas participadas 259 271 260 272 @author Rodrigo Boet (rboet at cenditel.gob.ve) 261 273 @copyright <a href='https://www.gnu.org/licenses/gpl-3.0.en.html'>GNU Public License versión 3 (GPLv3)</a> 262 @date 18-07-2017274 @date 28-09-2017 263 275 @version 1.0.0 264 276 """ 265 template_name = "participacion.create.simple.html" 277 template_name = "mi_participacion.html" 278 paginate_by = 1 266 279 267 280 def get_context_data(self, **kwargs): 268 281 """! 269 Metodo que permite cargar de nuevo valores en los datos decontexto de la vista270 271 @author Rodrigo Boet (rboet at cenditel.gob.ve) 272 @copyright GNU/GPLv2 273 @date 2 3-02-2017282 Metodo para cargar/obtener valores en el contexto de la vista 283 284 @author Rodrigo Boet (rboet at cenditel.gob.ve) 285 @copyright GNU/GPLv2 286 @date 28-03-2017 274 287 @param self <b>{object}</b> Objeto que instancia la clase 275 288 @param kwargs <b>{object}</b> Objeto que contiene los datos de contexto 276 289 @return Retorna los datos de contexto 277 290 """ 278 valores = {} 279 for pregunta in Pregunta.objects.filter(consulta_id=kwargs['pk']).all(): 280 label = '<label class="text-center">'+pregunta.texto_pregunta+'</label>' 281 campo = '' 282 if pregunta.tipo_pregunta.id == 1: 283 campo = '' 284 for opcion in Opcion.objects.filter(pregunta_id=pregunta.id).all(): 285 campo += '<label for="'+kwargs['pk']+'">'+opcion.texto_opcion+'</label><input type="radio" name="consulta_respuesta_radio_'+str(pregunta.id)+'" id="'+kwargs['pk']+'"value="'+str(opcion.id)+'" class="icheck">' 286 elif pregunta.tipo_pregunta.id == 2: 287 campo = '' 288 for opcion in Opcion.objects.filter(pregunta_id=pregunta.id).all(): 289 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">' 290 elif pregunta.tipo_pregunta.id > 2 and pregunta.tipo_pregunta.id < 5: 291 if(pregunta.tipo_pregunta.id == 3): 292 campo += '<label for="'+kwargs['pk']+'">Si</label><input type="radio" name="consulta_respuesta_sino_'+str(pregunta.id)+'" id="'+kwargs['pk']+'"value="Si" class="icheck">' 293 campo += '<label for="'+kwargs['pk']+'">No</label><input type="radio" name="consulta_respuesta_sino_'+str(pregunta.id)+'" id="'+kwargs['pk']+'"value="No" class="icheck">' 294 else: 295 campo += '<label for="'+kwargs['pk']+'">Si</label><input type="radio" name="consulta_respuesta_sino_'+str(pregunta.id)+'" id="'+kwargs['pk']+'"value="Si" class="icheck need_justification">' 296 campo += '<label for="'+kwargs['pk']+'">No</label><input type="radio" name="consulta_respuesta_sino_'+str(pregunta.id)+'" id="'+kwargs['pk']+'"value="No" class="icheck">' 297 campo += '<div id="div_justificar_'+kwargs['pk']+'" style="display:none;"><label>Indique con que instrumento legal en vigencia se relaciona su aporte</label>' 298 campo += '<textarea class="form-control" id="respuesta_justificar_'+kwargs['pk']+'" name="consulta_respuesta_justificar_'+str(pregunta.id)+'">' 299 campo += '</textarea></div>' 300 valores[pregunta.id] = {'label':label,'field':campo} 301 kwargs['preguntas'] = valores 302 return super(ParticipacionSimpleCreate, self).get_context_data(**kwargs) 303 304 def post(self,request,pk,id_objetivo): 305 """! 306 Metodo que sobreescribe el post del formulario 307 308 @author Rodrigo Boet (rboet at cenditel.gob.ve) 309 @copyright GNU/GPLv2 310 @date 20-03-2017 311 @param self <b>{object}</b> Objeto que instancia la clase 312 @param request <b>{object}</b> Objeto que instancia la petición 313 @param pk <b>{int}</b> Recibe el id de la consulta 314 @param id_ente <b>{int}</b> Recibe el id del ente 315 @return Retorna los datos de contexto 316 """ 317 data = dict(request.POST) 318 del data['csrfmiddlewaretoken'] 319 if self.request.is_ajax(): 320 for key in data.keys(): 321 parent_id = key.split("_")[-1] 322 if 'sino' in key: 323 value = True if data[key][0] == 'Si' else False 324 justify_id = 'consulta_respuesta_justificar_'+str(parent_id) 325 self.crear_respuesta_sino(parent_id,value,id_objetivo,self.request.user.id) 326 if(not value and justify_id in data.keys()): 327 respuesta = data[justify_id][0] 328 self.crear_respuesta_abierta(parent_id,respuesta,id_objetivo,self.request.user.id,True) 329 elif 'radio' in key or 'check' in key: 330 for value in data[key]: 331 self.crear_respuesta_opciones(value,id_objetivo,self.request.user.id) 332 return JsonResponse({"code":True}) 333 return redirect(reverse_lazy('participacion_busqueda',kwargs={'pk':pk})) 334 335 def crear_respuesta_sino(self,parent_id,value,id_objetivo,user_id): 336 """! 337 Metodo para crear una respuesta de si/no 338 339 @author Rodrigo Boet (rboet at cenditel.gob.ve) 340 @copyright GNU/GPLv2 341 @date 27-03-2017 342 @param self <b>{object}</b> Objeto que instancia la clase 343 @param parent_id <b>{int}</b> Recibe el número del id del padre 344 @param value <b>{bool}</b> Recibe el valor de la respuesta 345 @param id_objetivo <b>{int}</b> Recibe el id del objetivo 346 @param user_id <b>{int}</b> Recibe el id del user 347 @return Retorna los datos de contexto 348 """ 349 user = User.objects.get(id=user_id) 350 parent = Pregunta.objects.get(pk=parent_id) 351 respuesta = RespuestaSino() 352 respuesta.pregunta = parent 353 respuesta.respuesta = value 354 respuesta.user = user 355 respuesta.save() 291 context = super(MiParticipacion, self).get_context_data(**kwargs) 292 context['object_list'] = cargar_consultas() 356 293 357 def crear_respuesta_opciones(self,parent_id,id_objetivo,user_id): 358 """! 359 Metodo para crear una respuesta de selección simple y múltiple 360 361 @author Rodrigo Boet (rboet at cenditel.gob.ve) 362 @copyright GNU/GPLv2 363 @date 28-03-2017 364 @param self <b>{object}</b> Objeto que instancia la clase 365 @param parent_id <b>{int}</b> Recibe el número del id del padre 366 @param id_objetivo <b>{int}</b> Recibe el id del objetivo 367 @param user_id <b>{int}</b> Recibe el id del user 368 @return Retorna los datos de contexto 369 """ 370 user = User.objects.get(id=user_id) 371 parent = Opcion.objects.get(pk=parent_id) 372 respuesta = RespuestaOpciones() 373 respuesta.opcion = parent 374 respuesta.user = user 375 respuesta.save() 294 ## Implementación del paginador 295 paginator = Paginator(context['object_list'], self.paginate_by) 296 page = self.request.GET.get('page') 297 try: 298 context['page_obj'] = paginator.page(page) 299 context['object_list'] = context['page_obj'].object_list 300 except PageNotAnInteger: 301 context['page_obj'] = paginator.page(1) 302 context['object_list'] = context['page_obj'].object_list 303 except EmptyPage: 304 context['page_obj'] = paginator.page(paginator.num_pages) 305 context['object_list'] = context['page_obj'].object_list 306 return context 307
Nota: Vea TracChangeset
para ayuda en el uso del visor de conjuntos de cambios.