#2784
[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
ce8f351f 5from 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
33class ContratForm(forms.ModelForm, FormDate):
34
35 class Model:
36 model = Contrat
cf022e27 37
105dd778
OL
38class AyantDroitForm(forms.ModelForm, AjaxSelect):
39
ed4fbe26
OL
40 # ne fonctionne pas dans un inline
41 #nationalite = AutoCompleteSelectField('pays', help_text="Taper le nom ou le code du pays", required=False)
cf022e27
OL
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
105dd778
OL
51class EmployeAdminForm(forms.ModelForm, AjaxSelect):
52
ed4fbe26
OL
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)
105dd778
OL
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