source: firmaeventos/participantes/forms.py @ 45f784a

Last change on this file since 45f784a was 45f784a, checked in by lhernandez <lhernandez@…>, 6 years ago

Solventado error funcional del modelformset_factory

  • Property mode set to 100644
File size: 3.6 KB
Line 
1from django import forms
2from django.core.exceptions import NON_FIELD_ERRORS
3from django.forms import (
4       inlineformset_factory, modelform_factory, modelformset_factory, formset_factory
5   )
6
7from eventos.models import (
8    Evento
9    )
10from .models import *
11
12
13class 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='https://www.gnu.org/licenses/gpl-3.0.en.html'>GNU Public License versión 3 (GPLv3)</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
45class 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='https://www.gnu.org/licenses/gpl-3.0.en.html'>GNU Public License versión 3 (GPLv3)</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
79FormsetEventPartici = 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
87FormsetParticipanteEvento = modelform_factory(
88                                    Participante,
89                                    form=ParticiapanteForm,
90                                    fields=('nombres', 'apellidos',
91                                            'pasaporte', 'correo'))
92
93FormsetParticipanteEvento = modelformset_factory(
94                            Participante,
95                            form=FormsetParticipanteEvento,
96                            fields=('nombres', 'apellidos',
97                                    'pasaporte', 'correo'),
98                            extra=1)
Note: See TracBrowser for help on using the repository browser.