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.widgets |
---|
7 | # |
---|
8 | # Contiene las clases, atributos y métodos para los widgets a implementar en los formularios |
---|
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 | import logging |
---|
16 | |
---|
17 | from django.forms import MultiWidget, Select, TextInput |
---|
18 | from django.utils.translation import ugettext_lazy as _ |
---|
19 | |
---|
20 | from .constant import ( |
---|
21 | TIPO_DOCUMENTO_IDENTIFICACION |
---|
22 | ) |
---|
23 | |
---|
24 | """! |
---|
25 | Contiene el objeto que registra la vitacora de eventos del módulo base. |
---|
26 | (configuración en el settings de la aplicación) |
---|
27 | """ |
---|
28 | logger = logging.getLogger("base") |
---|
29 | |
---|
30 | |
---|
31 | class TipoDocumentoWidget(MultiWidget): |
---|
32 | """! |
---|
33 | Clase que agrupa los widgets de los campos del tipo de documento de identificación |
---|
34 | |
---|
35 | @author Ing. Roldan Vargas (rvargas at cenditel.gob.ve) |
---|
36 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
37 | @date 19-08-2016 |
---|
38 | @version 1.0.0 |
---|
39 | """ |
---|
40 | |
---|
41 | def __init__(self, attrs=None, *args, **kwargs): |
---|
42 | |
---|
43 | self.attrs = attrs or {} |
---|
44 | |
---|
45 | widgets = ( |
---|
46 | Select( |
---|
47 | attrs={ |
---|
48 | 'class': 'select2 form-control input-sm', 'data-toggle': 'tooltip', |
---|
49 | 'title': _("Seleccione el tipo de documento (cédula o pasaporte)") |
---|
50 | }, choices=TIPO_DOCUMENTO_IDENTIFICACION |
---|
51 | ), |
---|
52 | TextInput( |
---|
53 | attrs={ |
---|
54 | 'class': 'form-control text-center input-sm', 'placeholder': '00000000', 'data-mask': '00000000', |
---|
55 | 'data-toggle': 'tooltip', 'maxlength': '8', 'data-rule-required': 'true', 'size': '7', |
---|
56 | 'title': _("Indique el número de R.I.F., si es menor a 8 dígitos complete con ceros a la izquierda") |
---|
57 | } |
---|
58 | ) |
---|
59 | ) |
---|
60 | |
---|
61 | super(TipoDocumentoWidget, self).__init__(widgets, attrs, *args, **kwargs) |
---|
62 | |
---|
63 | def format_output(self, rendered_widgets): |
---|
64 | return ' - '.join(rendered_widgets) |
---|
65 | |
---|
66 | def decompress(self, value): |
---|
67 | if value: |
---|
68 | return [value[0], value[1:]] |
---|
69 | return [None, None] |
---|
70 | |
---|
71 | |
---|
72 | class TipoDocumentoWidgetReadOnly(MultiWidget): |
---|
73 | """! |
---|
74 | Clase que agrupa los widgets de los campos del tipo de documento de identificación para solo lectura |
---|
75 | |
---|
76 | @author Ing. Roldan Vargas (rvargas at cenditel.gob.ve) |
---|
77 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
78 | @date 19-08-2016 |
---|
79 | @version 1.0.0 |
---|
80 | """ |
---|
81 | |
---|
82 | def __init__(self, attrs=None, *args, **kwargs): |
---|
83 | |
---|
84 | self.attrs = attrs or {} |
---|
85 | |
---|
86 | widgets = ( |
---|
87 | TextInput( |
---|
88 | attrs={ |
---|
89 | 'class': 'form-control text-center', 'data-toggle': 'tooltip', 'readonly': 'readonly', |
---|
90 | 'title': _("Tipo de Documento (Cédula o Pasaporte)"), 'size': '1', |
---|
91 | } |
---|
92 | ), |
---|
93 | TextInput( |
---|
94 | attrs={ |
---|
95 | 'class': 'form-control text-center', 'readonly': 'readonly', |
---|
96 | 'data-toggle': 'tooltip', 'maxlength': '8', 'size': '7', |
---|
97 | 'title': _("Número del documento de identificación") |
---|
98 | } |
---|
99 | ) |
---|
100 | ) |
---|
101 | |
---|
102 | super(TipoDocumentoWidgetReadOnly, self).__init__(widgets, attrs, *args, **kwargs) |
---|
103 | |
---|
104 | def format_output(self, rendered_widgets): |
---|
105 | return ' - '.join(rendered_widgets) |
---|
106 | |
---|
107 | def decompress(self, value): |
---|
108 | if value: |
---|
109 | return [value[0], value[1:]] |
---|
110 | return [None, None] |
---|