select opt employe poste
[auf_rh_dae.git] / project / rh / forms.py
CommitLineData
84cbb4c5
OL
1# -*- encoding: utf-8 -*-
2
3from django import forms
105dd778
OL
4from ajax_select.fields import AutoCompleteSelectField
5from auf.django.references import models as ref
6from models import Dossier, Contrat, AyantDroit, Employe, Poste
7
8
9class 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', )
84cbb4c5
OL
16
17
18class 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:
3f5f3898 26 raise forms.ValidationError(u"La date de fin est antérieure à la date de début")
84cbb4c5
OL
27 return date_fin
28
105dd778
OL
29class PosteForm(forms.ModelForm, AjaxSelect):
30 implantation = AutoCompleteSelectField('implantations', help_text="Taper le nom de l'implantation ou sa région")
31
32 class Model:
33 model = Poste
84cbb4c5 34
105dd778
OL
35class DossierForm(forms.ModelForm, FormDate):
36
84cbb4c5
OL
37 class Model:
38 model = Dossier
39
40class ContratForm(forms.ModelForm, FormDate):
41
42 class Model:
43 model = Contrat
cf022e27 44
105dd778
OL
45class AyantDroitForm(forms.ModelForm, AjaxSelect):
46
47 nationalite = AutoCompleteSelectField('pays', help_text="Taper le nom ou le code du pays")
cf022e27
OL
48
49 def __init__(self, *args, **kwargs):
50 super(AyantDroitForm, self).__init__(*args, **kwargs)
51 self.fields['date_naissance'].widget = forms.widgets.DateInput()
52
53 class Meta:
54 model = AyantDroit
55
56
105dd778
OL
57class EmployeAdminForm(forms.ModelForm, AjaxSelect):
58
59 nationalite = AutoCompleteSelectField('pays', help_text="Taper le nom ou le code du pays")
60 pays = AutoCompleteSelectField('pays', help_text="Taper le nom ou le code du pays")
61
62 class Meta:
63 model = Employe
64
65 def __init__(self, *args, **kwargs):
66 super(EmployeAdminForm, self).__init__(*args, **kwargs)
67 self.fields['date_naissance'].widget = forms.widgets.DateInput()
68
69