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",
|
|
|
|
"picture",
|
|
|
|
"department",
|
|
|
|
"promotion",
|
|
|
|
"birth_date",
|
|
|
|
"thurne",
|
|
|
|
"text_field",
|
|
|
|
"printing",
|
|
|
|
"keep_me"
|
|
|
|
]
|
|
|
|
|
2020-01-15 21:27:37 +01:00
|
|
|
|
|
|
|
class SearchForm(forms.Form):
|
2020-02-08 11:02:39 +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-08 11:02:39 +01:00
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
cleaned_data = super().clean()
|
2020-02-08 14:48:44 +01:00
|
|
|
if (
|
|
|
|
not cleaned_data['name']
|
|
|
|
and not cleaned_data['year']
|
|
|
|
and not cleaned_data['department']
|
|
|
|
):
|
|
|
|
raise forms.ValidationError(('Tous les champs sont vides'), code='invalid')
|