1b08bc1c6a2f92a341d184d079307821bc2d5c76
[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 project.rh.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
34 class ContratForm(forms.ModelForm, FormDate):
35
36 class Model:
37 model = Contrat
38
39 class AyantDroitForm(forms.ModelForm, AjaxSelect):
40
41 # ne fonctionne pas dans un inline
42 #nationalite = AutoCompleteSelectField('pays', help_text="Taper le nom ou le code du pays", required=False)
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
52 class EmployeAdminForm(forms.ModelForm, AjaxSelect):
53
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)
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