1 | from django import forms |
---|
2 | from django.core.exceptions import NON_FIELD_ERRORS |
---|
3 | from django.forms import ( |
---|
4 | inlineformset_factory, modelform_factory |
---|
5 | ) |
---|
6 | |
---|
7 | from eventos.models import ( |
---|
8 | Evento |
---|
9 | ) |
---|
10 | from .models import * |
---|
11 | |
---|
12 | |
---|
13 | class ParticiapanteForm(forms.ModelForm): |
---|
14 | """! |
---|
15 | Clase que crea el formulario para el create or update del participante |
---|
16 | |
---|
17 | @author Ing. Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve) |
---|
18 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
19 | @date 19-11-2017 |
---|
20 | @version 1.0.0 |
---|
21 | """ |
---|
22 | |
---|
23 | class Meta: |
---|
24 | """! |
---|
25 | Clase que construye los meta datos del formulario |
---|
26 | """ |
---|
27 | model = Participante |
---|
28 | fields=('nombres', 'apellidos', 'pasaporte', 'correo') |
---|
29 | |
---|
30 | def __init__(self, *args, **kwargs): |
---|
31 | """! |
---|
32 | Funcion que construye los valores iniciales del formulario participante |
---|
33 | """ |
---|
34 | super(ParticiapanteForm, self).__init__(*args, **kwargs) |
---|
35 | self.fields['nombres'].widget.attrs.update( |
---|
36 | {'placeholder': 'Nombres'}) |
---|
37 | self.fields['apellidos'].widget.attrs.update( |
---|
38 | {'placeholder': 'Apellidos'}) |
---|
39 | self.fields['pasaporte'].widget.attrs.update( |
---|
40 | {'placeholder': 'Pasaporte'}) |
---|
41 | self.fields['correo'].widget.attrs.update( |
---|
42 | {'placeholder': 'Correo'}) |
---|
43 | |
---|
44 | |
---|
45 | class AddPartEventForm(forms.ModelForm): |
---|
46 | """! |
---|
47 | Clase que crea el formulario para añadir participante al evento |
---|
48 | |
---|
49 | @author Ing. Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve) |
---|
50 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
51 | @date 19-11-2017 |
---|
52 | @version 1.0.0 |
---|
53 | """ |
---|
54 | |
---|
55 | class Meta: |
---|
56 | """! |
---|
57 | Clase que construye los meta datos del formulario |
---|
58 | """ |
---|
59 | model = ParticipanteEvento |
---|
60 | exclude = ['firma', 'fk_evento'] |
---|
61 | error_messages = { |
---|
62 | NON_FIELD_ERRORS: { |
---|
63 | 'unique_together': "El participante ya se\ |
---|
64 | encuentra registrado en el evento.", |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | def __init__(self, *args, **kwargs): |
---|
69 | """! |
---|
70 | Funcion que construye los valores iniciales del participante evento |
---|
71 | """ |
---|
72 | super(AddPartEventForm, self).__init__(*args, **kwargs) |
---|
73 | self.fields['fk_participante'].empty_label = 'Seleccione Participante' |
---|
74 | self.fields['fk_participante'].widget.attrs.update( |
---|
75 | {'class': 'form-control'}) |
---|
76 | self.fields['fk_participante'].label = 'Participante' |
---|
77 | |
---|
78 | |
---|
79 | FormsetEventPartici = inlineformset_factory( |
---|
80 | Evento, ParticipanteEvento, |
---|
81 | form=AddPartEventForm, |
---|
82 | fields=('fk_participante',), |
---|
83 | fk_name='fk_evento', min_num=1, |
---|
84 | extra=0, validate_min=True, |
---|
85 | can_delete=True) |
---|
86 | |
---|
87 | FormsetParticipanteEvento = modelform_factory( |
---|
88 | Participante, |
---|
89 | form=ParticiapanteForm, |
---|
90 | fields=('nombres', 'apellidos', |
---|
91 | 'pasaporte', 'correo')) |
---|