1 | """ |
---|
2 | Sistema Estadístico Integral de Venezuela - (SEIVEN) |
---|
3 | |
---|
4 | Copyleft (@) 2015 CENDITEL nodo Mérida - https://mpv.cenditel.gob.ve/seiven |
---|
5 | """ |
---|
6 | ## @namespace base.forms |
---|
7 | # |
---|
8 | # Contiene las clases, atributos y métodos para los formularios a implementar en el módulo base |
---|
9 | # @author Ing. Roldan Vargas (rvargas at cenditel.gob.ve) |
---|
10 | # @author <a href='http://www.cenditel.gob.ve'>Centro Nacional de Desarrollo e Investigación en Tecnologías Libres |
---|
11 | # (CENDITEL) nodo Mérida - Venezuela</a> |
---|
12 | # @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
13 | from __future__ import unicode_literals |
---|
14 | |
---|
15 | from django.utils.encoding import python_2_unicode_compatible |
---|
16 | from django.utils.translation import ugettext_lazy as _ |
---|
17 | |
---|
18 | from .constant import ( |
---|
19 | TIPO_DOCUMENTO_IDENTIFICACION, FORTALEZA_CONTRASENHA |
---|
20 | ) |
---|
21 | from base.fields import ( |
---|
22 | TipoDocumentoField |
---|
23 | ) |
---|
24 | |
---|
25 | import logging |
---|
26 | |
---|
27 | from captcha.fields import CaptchaField, CaptchaTextInput |
---|
28 | from django import forms |
---|
29 | from django.forms import ( |
---|
30 | ModelForm, TextInput, EmailInput, CharField, EmailField, PasswordInput, |
---|
31 | Select, MultiWidget, MultiValueField, ChoiceField |
---|
32 | ) |
---|
33 | from django.contrib.auth.models import User |
---|
34 | |
---|
35 | |
---|
36 | """! |
---|
37 | Contiene el objeto que registra la vitacora de eventos del módulo base. |
---|
38 | (configuración en el settings de la aplicación) |
---|
39 | """ |
---|
40 | logger = logging.getLogger("base") |
---|
41 | |
---|
42 | |
---|
43 | @python_2_unicode_compatible |
---|
44 | class TipoDocumentoForm(forms.Form): |
---|
45 | """! |
---|
46 | Clase que contiene el campo del tipo de documento de identificación a incorporar en un formulario |
---|
47 | |
---|
48 | @author Ing. Roldan Vargas (rvargas at cenditel.gob.ve) |
---|
49 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
50 | @date 19-08-2016 |
---|
51 | @version 1.0.0 |
---|
52 | """ |
---|
53 | |
---|
54 | ## Tipo de documento de identificación |
---|
55 | tipo_documento = TipoDocumentoField() |
---|
56 | |
---|
57 | |
---|
58 | @python_2_unicode_compatible |
---|
59 | class ClaveForm(forms.Form): |
---|
60 | """! |
---|
61 | Clase que contiene el campo de contraseña a incorporar en un formulario |
---|
62 | |
---|
63 | @author Ing. Roldan Vargas (rvargas at cenditel.gob.ve) |
---|
64 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
65 | @date 19-08-2016 |
---|
66 | @version 1.0.0 |
---|
67 | """ |
---|
68 | |
---|
69 | ## Contraseña del usuario |
---|
70 | clave = CharField( |
---|
71 | label=_("Contraseña:"), max_length=30, widget=PasswordInput(attrs={ |
---|
72 | 'class': 'form-control input-sm', 'placeholder': _("contraseña de acceso"), 'data-toggle': 'tooltip', |
---|
73 | 'title': _("Indique la contraseña de acceso al sistema"), |
---|
74 | 'onkeyup': 'passwordStrength(this.value)' |
---|
75 | }) |
---|
76 | ) |
---|
77 | |
---|
78 | def clean_clave(self): |
---|
79 | """! |
---|
80 | Método que permite validar el campo de contraseña |
---|
81 | |
---|
82 | @author Ing. Roldan Vargas (rvargas 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 19-08-2016 |
---|
85 | @param self <b>{object}</b> Objeto que instancia la clase |
---|
86 | @return Devuelve un mensaje de error en caso de que la contraseña sea incorrecta, en caso contrario devuelve |
---|
87 | el valor actual del campo |
---|
88 | """ |
---|
89 | clave = self.cleaned_data['clave'] |
---|
90 | tipo_documento = "%s%s" % (self.data['tipo_documento_0'], self.data['tipo_documento_1']) |
---|
91 | |
---|
92 | if User.objects.filter(username=tipo_documento) and not User.objects.get(username=tipo_documento).check_password(clave): |
---|
93 | raise forms.ValidationError(_("Contraseña incorrecta")) |
---|
94 | |
---|
95 | return clave |
---|
96 | |
---|
97 | |
---|
98 | @python_2_unicode_compatible |
---|
99 | class CaptchaForm(forms.Form): |
---|
100 | """! |
---|
101 | Clase que contiene el campo de captcha a incorporar en un formulario |
---|
102 | |
---|
103 | @author Ing. Roldan Vargas (rvargas at cenditel.gob.ve) |
---|
104 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
105 | @date 19-08-2016 |
---|
106 | @version 1.0.0 |
---|
107 | """ |
---|
108 | |
---|
109 | ## Campo de validación de captcha |
---|
110 | captcha = CaptchaField( |
---|
111 | label=_("Captcha:"), widget=CaptchaTextInput(attrs={ |
---|
112 | 'class': 'form-control input-sm', 'placeholder': _("texto de la imagen"), |
---|
113 | 'data-toggle': 'tooltip', |
---|
114 | 'title': _("Indique el texto de la imagen") |
---|
115 | }) |
---|
116 | ) |
---|
117 | |
---|
118 | |
---|
119 | @python_2_unicode_compatible |
---|
120 | class CorreoForm(forms.Form): |
---|
121 | """! |
---|
122 | Clase que contiene el campo de correo electrónico a incorporar en un formulario |
---|
123 | |
---|
124 | @author Ing. Roldan Vargas (rvargas at cenditel.gob.ve) |
---|
125 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
126 | @date 19-08-2016 |
---|
127 | @version 1.0.0 |
---|
128 | """ |
---|
129 | |
---|
130 | ## Campo que contiene el correo electrónico |
---|
131 | correo = EmailField( |
---|
132 | label=_("Correo Electrónico"), widget=EmailInput(attrs={ |
---|
133 | 'class': 'form-control input-sm', 'placeholder': _("Indique su correo"), 'data-toggle': 'tooltip', |
---|
134 | 'title': _("Indique el correo electrónico") |
---|
135 | }) |
---|
136 | ) |
---|