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