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 consulta.ajax |
---|
8 | # |
---|
9 | # Clases basadas en ajax |
---|
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='https://www.gnu.org/licenses/gpl-3.0.en.html'>GNU Public License versión 3 (GPLv3)</a> |
---|
14 | # @version 1.0 |
---|
15 | |
---|
16 | from django.http import JsonResponse |
---|
17 | from .models import Pregunta, Opcion |
---|
18 | |
---|
19 | def pregunta_list(request,pk): |
---|
20 | """! |
---|
21 | Función para listar las preguntas relacionadas a una consulta |
---|
22 | |
---|
23 | @author Rodrigo Boet (rboet at cenditel.gob.ve) |
---|
24 | @copyright GNU/GPLv2 |
---|
25 | @date 17-02-2017 |
---|
26 | @param request <b>{object}</b> Objeto que mantiene la peticion |
---|
27 | @param pk <b>{int}</b> Recibe id de la consulta |
---|
28 | @return Retorna un Json con los datos |
---|
29 | """ |
---|
30 | preguntas = Pregunta.objects.filter(consulta_id=pk) |
---|
31 | if(preguntas): |
---|
32 | datos = [] |
---|
33 | for item in preguntas.all(): |
---|
34 | datos.append({"texto_pregunta":item.texto_pregunta,"tipo_pregunta":item.tipo_pregunta_id, |
---|
35 | "id":item.id}) |
---|
36 | return JsonResponse({'success':True,'preguntas':datos}) |
---|
37 | return JsonResponse({'success':False,'mensaje':'No se encontraron preguntas'}) |
---|
38 | |
---|
39 | def opciones_list(request,pk): |
---|
40 | """! |
---|
41 | Función para listar las opciones relacionadas a una pregunta |
---|
42 | |
---|
43 | @author Rodrigo Boet (rboet at cenditel.gob.ve) |
---|
44 | @copyright GNU/GPLv2 |
---|
45 | @date 20-02-2017 |
---|
46 | @param request <b>{object}</b> Objeto que mantiene la peticion |
---|
47 | @param pk <b>{int}</b> Recibe id de la pregunta |
---|
48 | @return Retorna un Json con los datos |
---|
49 | """ |
---|
50 | opciones = Opcion.objects.filter(pregunta_id=pk) |
---|
51 | if(opciones): |
---|
52 | datos = [] |
---|
53 | for item in opciones.all(): |
---|
54 | datos.append({"id":item.id, "texto_opcion":item.texto_opcion}) |
---|
55 | return JsonResponse({'success':True,'opciones':datos}) |
---|
56 | return JsonResponse({'success':False,'mensaje':'No se encontraron opciones'}) |
---|
57 | |
---|