select opt employe poste
[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 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
34
35 class DossierForm(forms.ModelForm, FormDate):
36
37 class Model:
38 model = Dossier
39
40 class ContratForm(forms.ModelForm, FormDate):
41
42 class Model:
43 model = Contrat
44
45 class AyantDroitForm(forms.ModelForm, AjaxSelect):
46
47 nationalite = AutoCompleteSelectField('pays', help_text="Taper le nom ou le code du pays")
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
57 class 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