[bf47591] | 1 | from django import forms |
---|
[8fa24c3] | 2 | from django.core.exceptions import NON_FIELD_ERRORS |
---|
[bf47591] | 3 | from django.forms import ( |
---|
[8fa24c3] | 4 | inlineformset_factory, modelform_factory |
---|
[bf47591] | 5 | ) |
---|
| 6 | |
---|
[8fa24c3] | 7 | from eventos.models import ( |
---|
[bf47591] | 8 | Evento |
---|
| 9 | ) |
---|
| 10 | from .models import * |
---|
| 11 | |
---|
[8fa24c3] | 12 | |
---|
[bf47591] | 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) |
---|
[5dea5ff] | 18 | @copyright <a href='https://www.gnu.org/licenses/gpl-3.0.en.html'>GNU Public License versión 3 (GPLv3)</a> |
---|
[bf47591] | 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 |
---|
[8fa24c3] | 28 | fields=('nombres', 'apellidos', 'pasaporte', 'correo') |
---|
[bf47591] | 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( |
---|
[8fa24c3] | 36 | {'placeholder': 'Nombres'}) |
---|
[bf47591] | 37 | self.fields['apellidos'].widget.attrs.update( |
---|
[8fa24c3] | 38 | {'placeholder': 'Apellidos'}) |
---|
| 39 | self.fields['pasaporte'].widget.attrs.update( |
---|
| 40 | {'placeholder': 'Pasaporte'}) |
---|
[bf47591] | 41 | self.fields['correo'].widget.attrs.update( |
---|
[8fa24c3] | 42 | {'placeholder': 'Correo'}) |
---|
[bf47591] | 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) |
---|
[5dea5ff] | 50 | @copyright <a href='https://www.gnu.org/licenses/gpl-3.0.en.html'>GNU Public License versión 3 (GPLv3)</a> |
---|
[bf47591] | 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 | |
---|
[8fa24c3] | 79 | FormsetEventPartici = inlineformset_factory( |
---|
[bf47591] | 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) |
---|
[8fa24c3] | 86 | |
---|
| 87 | FormsetParticipanteEvento = modelform_factory( |
---|
| 88 | Participante, |
---|
| 89 | form=ParticiapanteForm, |
---|
| 90 | fields=('nombres', 'apellidos', |
---|
| 91 | 'pasaporte', 'correo')) |
---|