2020-01-15 20:58:10 +01:00
|
|
|
from django import forms
|
2020-02-08 11:02:39 +01:00
|
|
|
from fiches.models import Profile, Department
|
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
|
|
|
|
fields = [
|
|
|
|
"full_name",
|
|
|
|
"nickname",
|
2020-02-19 21:42:36 +01:00
|
|
|
"pronoun",
|
2020-01-27 19:58:25 +01:00
|
|
|
"picture",
|
|
|
|
"department",
|
|
|
|
"promotion",
|
|
|
|
"birth_date",
|
|
|
|
"thurne",
|
|
|
|
"text_field",
|
|
|
|
"printing",
|
2020-02-13 00:11:28 +01:00
|
|
|
"keep_me",
|
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")
|