1bdbe1978322513a8963d59ba758cdddbb693fc6
[auf_rh_dae.git] / project / rh / forms.py
1 # -*- encoding: utf-8 -*-
2
3 from django import forms
4 from ajax_select.fields import AutoCompleteSelectField
5 from models import Dossier, Contrat, AyantDroit, Employe
6
7
8 class AjaxSelect(object):
9
10 class Media:
11 css = {
12 'all': ('jquery-autocomplete/jquery.autocomplete.css', 'css/select.css', )
13 }
14 js = ('js/jquery-1.5.1.min.js', 'jquery-autocomplete/jquery.autocomplete.js', )
15
16
17 class FormDate(object):
18
19 def clean_date_fin(self):
20 date_fin = self.cleaned_data['date_fin']
21 if date_fin is None:
22 return date_fin
23 date_debut = self.cleaned_data['date_debut']
24 if date_fin < date_debut:
25 raise forms.ValidationError(u"La date de fin est antérieure à la date de début")
26 return date_fin
27
28 class DossierForm(forms.ModelForm, FormDate):
29
30 class Model:
31 model = Dossier
32
33 class ContratForm(forms.ModelForm, FormDate):
34
35 class Model:
36 model = Contrat
37
38 class AyantDroitForm(forms.ModelForm, AjaxSelect):
39
40 # ne fonctionne pas dans un inline
41 #nationalite = AutoCompleteSelectField('pays', help_text="Taper le nom ou le code du pays", required=False)
42
43 def __init__(self, *args, **kwargs):
44 super(AyantDroitForm, self).__init__(*args, **kwargs)
45 self.fields['date_naissance'].widget = forms.widgets.DateInput()
46
47 class Meta:
48 model = AyantDroit
49
50
51 class EmployeAdminForm(forms.ModelForm, AjaxSelect):
52
53 nationalite = AutoCompleteSelectField('pays', help_text="Taper le nom ou le code du pays", required=False)
54 pays = AutoCompleteSelectField('pays', help_text="Taper le nom ou le code du pays", required=False)
55
56 class Meta:
57 model = Employe
58
59 def __init__(self, *args, **kwargs):
60 super(EmployeAdminForm, self).__init__(*args, **kwargs)
61 self.fields['date_naissance'].widget = forms.widgets.DateInput()
62
63