PEP8
[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
6fb68b2f
DB
5from project.rh.models import Dossier, Contrat, AyantDroit, Employe, \
6 ResponsableImplantation
105dd778
OL
7
8
9class AjaxSelect(object):
10
11 class Media:
12 css = {
00119a5d
EMS
13 'all': (
14 'jquery-autocomplete/jquery.autocomplete.css',
15 'css/select.css',
16 )
105dd778 17 }
00119a5d
EMS
18 js = (
19 'js/jquery-1.5.1.min.js',
20 'jquery-autocomplete/jquery.autocomplete.js',
21 )
84cbb4c5
OL
22
23
24class FormDate(object):
25
26 def clean_date_fin(self):
27 date_fin = self.cleaned_data['date_fin']
28 if date_fin is None:
00119a5d 29 return date_fin
84cbb4c5
OL
30 date_debut = self.cleaned_data['date_debut']
31 if date_fin < date_debut:
00119a5d
EMS
32 raise forms.ValidationError(
33 u"La date de fin est antérieure à la date de début"
34 )
84cbb4c5
OL
35 return date_fin
36
00119a5d 37
105dd778 38class DossierForm(forms.ModelForm, FormDate):
00119a5d 39
84cbb4c5
OL
40 class Model:
41 model = Dossier
42
6bee05ff 43
84cbb4c5
OL
44class ContratForm(forms.ModelForm, FormDate):
45
46 class Model:
47 model = Contrat
cf022e27 48
00119a5d 49
105dd778
OL
50class AyantDroitForm(forms.ModelForm, AjaxSelect):
51
ed4fbe26 52 # ne fonctionne pas dans un inline
cf022e27
OL
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
105dd778
OL
62class EmployeAdminForm(forms.ModelForm, AjaxSelect):
63
00119a5d
EMS
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 )
105dd778
OL
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
6fb68b2f
DB
79class ResponsableInlineForm(forms.ModelForm):
80 employes_actifs = Employe.objects.actifs()
81 employe = forms.ModelChoiceField(queryset=employes_actifs)
82
83 class Meta:
84 model = ResponsableImplantation