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