contrat échus
[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 auf.django.references import models as ref
6 from models import Dossier, Contrat, AyantDroit, Employe, Poste
7
8
9 class AjaxSelect(object):
10
11 class Media:
12 css = {
13 'all': ('jquery-autocomplete/jquery.autocomplete.css', 'css/select.css', )
14 }
15 js = ('js/jquery-1.5.1.min.js', 'jquery-autocomplete/jquery.autocomplete.js', )
16
17
18 class FormDate(object):
19
20 def clean_date_fin(self):
21 date_fin = self.cleaned_data['date_fin']
22 if date_fin is None:
23 return date_fin
24 date_debut = self.cleaned_data['date_debut']
25 if date_fin < date_debut:
26 raise forms.ValidationError(u"La date de fin est antérieure à la date de début")
27 return date_fin
28
29 class DossierForm(forms.ModelForm, FormDate):
30
31 class Model:
32 model = Dossier
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