7b15ddb4a199b2a9af7868f9999f145d376eeb76
[auf_rh_dae.git] / project / rh / forms.py
1 # -*- encoding: utf-8 -*-
2
3 from django import forms
4 from models import Dossier, Contrat, AyantDroit
5
6
7 class FormDate(object):
8
9 def clean_date_fin(self):
10 date_fin = self.cleaned_data['date_fin']
11 if date_fin is None:
12 return date_fin
13 date_debut = self.cleaned_data['date_debut']
14 if date_fin < date_debut:
15 raise forms.ValidationError(u"La date de fin est antérieure à la date de début")
16 return date_fin
17
18 class DossierForm(forms.ModelForm, FormDate):
19
20 class Model:
21 model = Dossier
22
23 class ContratForm(forms.ModelForm, FormDate):
24
25 class Model:
26 model = Contrat
27
28 class AyantDroitForm(forms.ModelForm):
29
30 def __init__(self, *args, **kwargs):
31 super(AyantDroitForm, self).__init__(*args, **kwargs)
32 self.fields['date_naissance'].widget = forms.widgets.DateInput()
33
34 class Meta:
35 model = AyantDroit
36
37