2020-01-15 20:58:10 +01:00
|
|
|
from django import forms
|
2020-09-17 15:46:16 +02:00
|
|
|
from django.forms.models import inlineformset_factory
|
2021-01-28 01:04:10 +01:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
|
|
|
from fiches.models import Address, Department, Mail, Phone, Profile, Social
|
2020-01-15 20:58:10 +01:00
|
|
|
|
2020-01-27 19:58:25 +01:00
|
|
|
|
2020-01-15 20:58:10 +01:00
|
|
|
class ProfileForm(forms.ModelForm):
|
2020-01-27 19:58:25 +01:00
|
|
|
class Meta:
|
|
|
|
model = Profile
|
2020-09-16 15:38:38 +02:00
|
|
|
exclude = ["user"]
|
2020-01-27 19:58:25 +01:00
|
|
|
|
2020-01-15 21:27:37 +01:00
|
|
|
|
|
|
|
class SearchForm(forms.Form):
|
2021-01-28 01:04:10 +01:00
|
|
|
name = forms.CharField(label=_("Nom/Surnom"), max_length=1023, required=False)
|
|
|
|
year = forms.IntegerField(label=_("Promotion"), required=False)
|
2020-02-08 14:48:44 +01:00
|
|
|
department = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=Department.objects.all(), required=False
|
2020-02-12 23:21:24 +01:00
|
|
|
)
|
2020-02-08 11:02:39 +01:00
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
cleaned_data = super().clean()
|
2020-02-08 14:48:44 +01:00
|
|
|
if (
|
2020-02-13 00:11:28 +01:00
|
|
|
not cleaned_data["name"]
|
|
|
|
and not cleaned_data["year"]
|
|
|
|
and not cleaned_data["department"]
|
2020-02-08 14:48:44 +01:00
|
|
|
):
|
2021-01-28 01:04:10 +01:00
|
|
|
raise forms.ValidationError(_("Tous les champs sont vides"), code="invalid")
|
2020-09-16 15:38:38 +02:00
|
|
|
|
|
|
|
|
2020-09-17 15:46:16 +02:00
|
|
|
PhoneFormSet = inlineformset_factory(Profile, Phone, exclude=[])
|
2020-09-16 15:38:38 +02:00
|
|
|
|
2020-09-17 15:46:16 +02:00
|
|
|
SocialFormSet = inlineformset_factory(Profile, Social, exclude=[])
|
2020-09-16 15:38:38 +02:00
|
|
|
|
2020-09-17 15:46:16 +02:00
|
|
|
MailFormSet = inlineformset_factory(Profile, Mail, exclude=[])
|
2020-09-16 15:38:38 +02:00
|
|
|
|
2020-09-17 15:46:16 +02:00
|
|
|
AddressFormSet = inlineformset_factory(Profile, Address, exclude=[])
|