annuaire-eleves/fiches/forms.py

52 lines
1.2 KiB
Python
Raw Normal View History

2020-01-15 20:58:10 +01:00
from django import forms
2020-09-16 15:38:38 +02:00
from fiches.models import Profile, Department, Phone, Social, Mail, Address
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):
2020-02-13 00:11:28 +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
):
2020-02-13 00:11:28 +01:00
raise forms.ValidationError(("Tous les champs sont vides"), code="invalid")
2020-09-16 15:38:38 +02:00
class PhoneForm(forms.BaseModelFormSet):
class Meta:
model = Phone
exclude = []
class SocialForm(forms.ModelForm):
class Meta:
model = Social
exclude = []
class MailForm(forms.ModelForm):
class Meta:
model = Mail
exclude = []
class AddressForm(forms.ModelForm):
class Meta:
model = Address
exclude = []