import avec project.
[auf_rh_dae.git] / project / rh / forms.py
CommitLineData
84cbb4c5
OL
1# -*- encoding: utf-8 -*-
2
3from django import forms
105dd778 4from ajax_select.fields import AutoCompleteSelectField
75f0e87b 5from project.rh.models import Dossier, Contrat, AyantDroit, Employe
105dd778
OL
6
7
8class 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', )
84cbb4c5
OL
15
16
17class 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:
3f5f3898 25 raise forms.ValidationError(u"La date de fin est antérieure à la date de début")
84cbb4c5
OL
26 return date_fin
27
105dd778
OL
28class DossierForm(forms.ModelForm, FormDate):
29
84cbb4c5
OL
30 class Model:
31 model = Dossier
32
6bee05ff 33
84cbb4c5
OL
34class ContratForm(forms.ModelForm, FormDate):
35
36 class Model:
37 model = Contrat
cf022e27 38
105dd778
OL
39class AyantDroitForm(forms.ModelForm, AjaxSelect):
40
ed4fbe26
OL
41 # ne fonctionne pas dans un inline
42 #nationalite = AutoCompleteSelectField('pays', help_text="Taper le nom ou le code du pays", required=False)
cf022e27
OL
43
44 def __init__(self, *args, **kwargs):
45 super(AyantDroitForm, self).__init__(*args, **kwargs)
46 self.fields['date_naissance'].widget = forms.widgets.DateInput()
47
48 class Meta:
49 model = AyantDroit
50
51
105dd778
OL
52class EmployeAdminForm(forms.ModelForm, AjaxSelect):
53
ed4fbe26
OL
54 nationalite = AutoCompleteSelectField('pays', help_text="Taper le nom ou le code du pays", required=False)
55 pays = AutoCompleteSelectField('pays', help_text="Taper le nom ou le code du pays", required=False)
105dd778
OL
56
57 class Meta:
58 model = Employe
59
60 def __init__(self, *args, **kwargs):
61 super(EmployeAdminForm, self).__init__(*args, **kwargs)
62 self.fields['date_naissance'].widget = forms.widgets.DateInput()
63
64