source: sapic/explicacion_situacional/forms.py @ 1c21737

Last change on this file since 1c21737 was 39b8a44, checked in by Manuel Zambrano <mzambrano595@…>, 6 años ago

Correcion del sub-modulo caracterizacion politica, implementacion de la funcion editar respuestas, correccion del campo tipo_pregunta en el pk:181 de initial_data_preguntas.json

  • Propiedad mode establecida a 100644
File size: 9.0 KB
Línea 
1# -*- coding: utf-8 -*-
2"""
3Sistema Automatizado de Planificación Integral Comunal SAPIC
4
5Copyleft (@) 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.forms
8#
9# Formularios correspondientes a la explicacion situacional
10# @author Ing. Leonel Paolo Hernandez Macchiarulo (lhernandez 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
16from django.core.exceptions import ValidationError
17from django.contrib.gis import forms
18from django.forms.fields import (
19    CharField,
20    BooleanField,
21)
22
23
24from explicacion_situacional.modelsExplicacion.modelsExplicacionesSituacional import *
25
26from explicacion_situacional.modelsEncuestas.modelsParticipacion import *
27
28
29class ExplicacionForms(forms.ModelForm):
30    """!
31    Clase que permite crear el formulario para la explicacion situacional
32
33    @author Ing. Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve)
34    @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a>
35    @date 09-01-2017
36    @version 1.0.0
37    """
38
39    class Meta:
40        """!
41        Clase que construye los meta datos del formulario
42
43        @author Ing. Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve)
44        @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a>
45        @date 18-09-2017
46        @version 1.0.0
47        """
48        model = ExplicacionSituacional
49        fields = '__all__'
50
51    def __init__(self, *args, **kwargs):
52        """!
53        Funcion que muestra el init del formulario
54
55        @author Ing. Leonel P. Hernandez M. (lhernandez 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 18-09-2017
58        """
59        super(ExplicacionForms, self).__init__(*args, **kwargs)
60        self.fields['fk_organizacion'].widget.attrs.update({
61                                      'class': 'form-control'})
62        self.fields['fk_organizacion'].empty_label = 'Seleccione la \
63                                                     organizacion social'
64        self.fields['fk_organizacion'].label = 'Organizacion Social'
65        self.fields['fk_organizacion'].required = True
66
67        self.fields['coordenadas'].widget = forms.OSMWidget.template_name = 'openlayers-es.html'
68        self.fields['coordenadas'].widget = forms.OSMWidget(attrs={
69                                    'default_zoom': 5.2, 'map_width': 600,
70                                    'map_height': 400, 'default_lat': 8,
71                                    'default_lon': -66})
72        self.fields['coordenadas'].required = True
73
74        self.fields['map_cartografico'].widget.attrs.update({'class':'form-control',
75                                                   'data-show-preview':'true',
76                                                   'accept':'image/*'})
77        self.fields['map_cartografico'].label = 'Mapa cartografico'
78        self.fields['map_cartografico'].required = True
79
80
81
82class UbicacionForms(forms.Form):
83    """!
84    Clase que permite crear el formulario para el tipo de preguntas que requieren ubicacion
85
86    @author Ing. Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve)
87    @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a>
88    @date 20-09-2017
89    @version 1.0.0
90    """
91    ubicacion = CharField()
92
93    class Meta:
94        """!
95        Clase que construye los meta datos del formulario
96
97        @author Ing. Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve)
98        @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a>
99        @date 18-09-2017
100        @version 1.0.0
101        """
102        fields = ('ubicacion')
103
104    def __init__(self, *args, **kwargs):
105        """!
106        Funcion que muestra el init del formulario
107
108        @author Ing. Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve)
109        @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a>
110        @date 18-09-2017
111        """
112        super(UbicacionForms, self).__init__(*args, **kwargs)
113
114        self.fields['ubicacion'].widget = forms.OSMWidget.template_name = 'openlayers-es.html'
115        self.fields['ubicacion'].widget = forms.OSMWidget(attrs={
116                                    'default_zoom': 5.2, 'map_width': 600,
117                                    'map_height': 400, 'default_lat': 8,
118                                    'default_lon': -66})
119        self.fields['ubicacion'].required = True
120
121class RespuestaSinoForm(forms.Form):
122    """!
123    Clase que permite crear el formulario para las respuestas de tipo SiNo
124
125    @author Manuel Zambrano
126    @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a>
127    @date 29-08-2018
128    @version 1.0.0
129    """
130
131    respuesta = forms.BooleanField(label='Respuesta',
132                                widget=forms.Select(choices=((True,'Si'),
133                                                            (False,'No')
134                                                            )
135                                                    ),
136                                required=False
137                                )
138    justificacion = forms.CharField(label='Respuesta', 
139                                    widget=forms.Textarea(),
140                                    required=False,
141                                    min_length = 128,
142                                    ) 
143
144    def __init__(self,*arg,**kwargs):
145        """!
146        Funcion que muestra el init del formulario
147
148        @author Manuel Zambrano
149        @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a>
150        @date 29-08-2018
151        @version 1.0.0
152        """
153        super(RespuestaSinoForm, self).__init__(*arg,**kwargs)
154        self.fields['justificacion'].widget.attrs.update({'placeholder': 'Justificacion','style':'width:370px;height:191px;'})
155
156    def clean(self):
157        """!
158        Funcion que sobreescribe el metodo clean() de la clase, validación para el campo de justificacion 
159
160        @author Manuel Zambrano
161        @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a>
162        @date 29-08-2018
163        @version 1.0.0
164        """
165        cleaned_data = super(RespuestaSinoForm,self).clean()
166        clean_respuesta = cleaned_data.get('respuesta')
167        clean_justificacion = cleaned_data.get('justificacion')
168        if not clean_respuesta:
169            if not clean_justificacion:
170                raise forms.ValidationError(
171                "Verifique el campo de justificacion",
172                code = "justificacion_error"
173                )
174
175class RespuestaAbiertaForm(forms.Form):
176    """!
177    Clase que permite crear el formulario para las respuestas de tipo Abierta
178
179    @author Manuel Zambrano
180    @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a>
181    @date 29-08-2018
182    @version 1.0.0
183    """
184
185    respuesta = forms.CharField(label='Respuesta', 
186                                widget=forms.Textarea(),
187                                min_length=128
188                                )
189
190    def __init__(self,*arg,**kwargs):
191        """!
192        Funcion que muestra el init del formulario
193
194        @author Manuel Zambrano
195        @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a>
196        @date 29-08-2018
197        @version 1.0.0
198        """
199       
200        super(RespuestaAbiertaForm, self).__init__(*arg,**kwargs)
201        self.fields['respuesta'].widget.attrs.update({'placeholder': 'Respuesta','style':'width:370px;height:191px;'})
202
203class RespuestaOpcionesForm(forms.Form):
204    """!
205    Clase que permite crear el formulario para las respuestas de tipo Opciones
206
207    @author Manuel Zambrano
208    @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a>
209    @date 29-08-2018
210    @version 1.0.0
211    """
212
213    respuesta = forms.ModelChoiceField(label = 'Opcion', 
214                                    queryset = Opcion.objects.all(),
215                                    required=True, 
216                                    empty_label=None
217                                    )
218
219    def __init__(self,*arg,**kwargs):
220        """!
221        Funcion que muestra el init del formulario
222
223        @author Manuel Zambrano
224        @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a>
225        @date 29-08-2018
226        @version 1.0.0
227        """
228
229        super(RespuestaOpcionesForm, self).__init__(*arg,**kwargs)
230
231   
232       
233
234       
235       
236       
237       
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.