9bdb6744f9a05ea78fea79fce553ea1de29ef3de
[auf_rh_dae.git] / project / rh / catalogues.py
1 # -*- encoding: utf-8 -*-
2
3 from django.db.models import Q
4 from auf.django.references import models as ref
5 import models as rh
6
7 class Pays(object):
8 fk_key = "code"
9
10 def get_query(self,q,request):
11 pays = ref.Pays.objects.filter(Q(nom__icontains=q) | Q(code__icontains=q))
12 return pays
13
14 def format_result(self, pays):
15 return unicode(pays)
16
17 def format_item(self, pays):
18 return self.format_result(pays)
19
20 def get_objects(self, ids):
21 return ref.Pays.objects.filter(code__in=ids)
22
23
24 class Implantation(object):
25
26 def get_query(self,q,request):
27 f = Q(nom__icontains=q) | Q(nom_court__icontains=q) | Q(nom_long__icontains=q) | Q(region__nom__icontains=q)
28 implantations = ref.Implantation.objects.filter(f)
29 return implantations
30
31 def format_result(self, implantation):
32 statut = implantation.statut
33 if implantation.statut == 0:
34 statut = u"Jamais ouverte OU fermée"
35 if implantation.statut == 1:
36 statut = u"Ouverte"
37 if implantation.statut == 2:
38 statut = u"Fermée"
39 if implantation.statut == 3:
40 statut = u"Ouverte imminente"
41
42 return u"%s (%s) [%s]" % (implantation.nom, implantation.id, statut)
43
44 def format_item(self, implantation):
45 return self.format_result(implantation)
46
47 def get_objects(self, ids):
48 return ref.Implantation.objects.filter(id__in=ids)
49
50 class TypePoste(object):
51
52 def get_query(self,q,request):
53 f = Q(nom__icontains=q) | Q(nom_feminin__icontains=q) | Q(categorie_emploi__nom__icontains=q)
54 typepostes = rh.TypePoste.objects.filter(f)
55 return typepostes
56
57 def format_result(self, typeposte):
58 return unicode(typeposte)
59
60 def format_item(self, typeposte):
61 return self.format_result(typeposte)
62
63 def get_objects(self, ids):
64 return rh.TypePoste.objects.filter(id__in=ids)
65
66 class Poste(object):
67
68 def get_query(self,q,request):
69 f = Q(nom__icontains=q) | Q(type_poste__nom__icontains=q) | Q(rh_dossiers__employe__nom__icontains=q) | Q(rh_dossiers__employe__prenom__icontains=q)
70 postes = rh.Poste.objects.filter(f).distinct()
71 return postes
72
73 def format_result(self, poste):
74 return unicode(poste)
75
76 def format_item(self, poste):
77 return self.format_result(poste)
78
79 def get_objects(self, ids):
80 return rh.Poste.objects.filter(id__in=ids)
81
82 class ValeurPoint(object):
83
84 def get_query(self,q,request):
85 f = Q(devise__code__icontains=q) | Q(implantation__nom__icontains=q)
86 points = rh.ValeurPoint.objects.select_related('devise', 'implantation').filter(f)
87 return points
88
89 def format_result(self, point):
90 return unicode(point)
91
92 def format_item(self, point):
93 return self.format_result(point)
94
95 def get_objects(self, ids):
96 return rh.ValeurPoint.objects.filter(id__in=ids)
97
98 class Employe(object):
99
100 def get_query(self,q,request):
101 f = Q(nom__icontains=q) | Q(prenom__icontains=q) | Q(nom_affichage__icontains=q)
102 employes = rh.Employe.objects.filter(f)
103 return employes
104
105 def format_result(self, employe):
106 return unicode(employe)
107
108 def format_item(self, employe):
109 return self.format_result(employe)
110
111 def get_objects(self, ids):
112 return rh.Employe.objects.filter(id__in=ids)
113
114 class Dossier(object):
115
116 def get_query(self,q,request):
117 f = Q(poste__nom=q) | Q(poste__type_poste__nom=q) | Q(employe__nom__icontains=q) | Q(employe__prenom__icontains=q) | Q(employe__nom_affichage__icontains=q)
118 dossiers = rh.Dossier.objects.filter(f)
119 return dossiers
120
121 def format_result(self, dossier):
122 return unicode(dossier)
123
124 def format_item(self, dossier):
125 return self.format_result(dossier)
126
127 def get_objects(self, ids):
128 return rh.Dossier.objects.filter(id__in=ids)