[#2658] Retrait du hack app_label() dans rh.models
[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
6 from project.rh import models as rh
7
8
9 class Pays(object):
10 fk_key = "code"
11
12 def get_query(self, q, request):
13 pays = ref.Pays.objects.filter(
14 Q(nom__icontains=q) | Q(code__icontains=q)
15 )
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
28 class Implantation(object):
29
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 )
35 return implantations
36
37 def format_result(self, implantation):
38 statut = implantation.statut
39 if implantation.statut == 0:
40 statut = u"Jamais ouverte OU fermée"
41 if implantation.statut == 1:
42 statut = u"Ouverte"
43 if implantation.statut == 2:
44 statut = u"Fermée"
45 if implantation.statut == 3:
46 statut = u"Ouverte imminente"
47
48 return u"%s (%s) [%s]" % (implantation.nom, implantation.id, statut)
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
56
57 class TypePoste(object):
58
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 )
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
75
76 class Poste(object):
77
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()
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
95
96 class ValeurPoint(object):
97
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 )
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)
115
116
117 class Employe(object):
118
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 )
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
135
136 class Dossier(object):
137
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 )
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)