a1671a2d52aae0a016ab57c7ba84f3bb7ea2629d
[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 ResponsableImplantation
7
8
9 class AjaxSelect(object):
10
11 class Media:
12 css = {
13 'all': (
14 'jquery-autocomplete/jquery.autocomplete.css',
15 'css/select.css',
16 )
17 }
18 js = (
19 'js/jquery-1.5.1.min.js',
20 'jquery-autocomplete/jquery.autocomplete.js',
21 )
22
23
24 class FormDate(object):
25
26 def clean_date_fin(self):
27 date_fin = self.cleaned_data['date_fin']
28 if date_fin is None:
29 return date_fin
30 date_debut = self.cleaned_data['date_debut']
31 if date_fin < date_debut:
32 raise forms.ValidationError(
33 u"La date de fin est antérieure à la date de début"
34 )
35 return date_fin
36
37
38 class DossierForm(forms.ModelForm, FormDate):
39
40 class Model:
41 model = Dossier
42
43
44 class ContratForm(forms.ModelForm, FormDate):
45
46 class Model:
47 model = Contrat
48
49
50 class AyantDroitForm(forms.ModelForm, AjaxSelect):
51
52 # ne fonctionne pas dans un inline
53
54 def __init__(self, *args, **kwargs):
55 super(AyantDroitForm, self).__init__(*args, **kwargs)
56 self.fields['date_naissance'].widget = forms.widgets.DateInput()
57
58 class Meta:
59 model = AyantDroit
60
61
62 class EmployeAdminForm(forms.ModelForm, AjaxSelect):
63
64 nationalite = AutoCompleteSelectField(
65 'pays', help_text="Taper le nom ou le code du pays", required=False
66 )
67 pays = AutoCompleteSelectField(
68 'pays', help_text="Taper le nom ou le code du pays", required=False
69 )
70
71 class Meta:
72 model = Employe
73
74 def __init__(self, *args, **kwargs):
75 super(EmployeAdminForm, self).__init__(*args, **kwargs)
76 self.fields['date_naissance'].widget = forms.widgets.DateInput()
77
78
79 class ResponsableInlineForm(forms.ModelForm):
80 employes_actifs = Employe.objects.actifs()
81 employe = forms.ModelChoiceField(queryset=employes_actifs)
82
83 class Meta:
84 model = ResponsableImplantation