Fix for odette
[auf_rh_dae.git] / project / rh / catalogues.py
CommitLineData
105dd778
OL
1# -*- encoding: utf-8 -*-
2
3c927c12 3import datetime
105dd778 4from django.db.models import Q
e949324b 5
105dd778 6from auf.django.references import models as ref
4ba84959 7
45f203cb
EMS
8from project.groups import get_employe_from_user
9from project.permissions import user_gere_obj_de_sa_region
4ba84959
EMS
10from project.rh import models as rh
11
105dd778
OL
12
13class Pays(object):
ad1eb1db 14 fk_key = "code"
105dd778 15
4ba84959
EMS
16 def get_query(self, q, request):
17 pays = ref.Pays.objects.filter(
18 Q(nom__icontains=q) | Q(code__icontains=q)
19 )
105dd778
OL
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
32class Implantation(object):
33
4ba84959
EMS
34 def get_query(self, q, request):
35 implantations = ref.Implantation.objects.filter(
36 Q(nom__icontains=q) | Q(nom_court__icontains=q) |
b0cf30b8 37 Q(nom_long__icontains=q) | Q(zone_administrative__nom__icontains=q)
4ba84959 38 )
45f203cb 39 if user_gere_obj_de_sa_region(request.user):
26b037fd
EMS
40 employe = get_employe_from_user(request.user)
41 implantations = implantations.filter(
b0cf30b8 42 zone_administrative=employe.implantation.zone_administrative
26b037fd 43 )
105dd778
OL
44 return implantations
45
46 def format_result(self, implantation):
94af2307
OL
47 statut = implantation.statut
48 if implantation.statut == 0:
94ecd5bb 49 statut = u"Jamais ouverte OU fermée"
94af2307
OL
50 if implantation.statut == 1:
51 statut = u"Ouverte"
52 if implantation.statut == 2:
53 statut = u"Fermée"
54 if implantation.statut == 3:
94ecd5bb 55 statut = u"Ouverte imminente"
94af2307
OL
56
57 return u"%s (%s) [%s]" % (implantation.nom, implantation.id, statut)
105dd778
OL
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
4ba84959 65
105dd778
OL
66class TypePoste(object):
67
4ba84959
EMS
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 )
105dd778
OL
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
4ba84959 84
105dd778
OL
85class Poste(object):
86
4ba84959 87 def get_query(self, q, request):
26b037fd 88 postes = rh.Poste.objects.ma_region_ou_service(request.user).filter(
4ba84959
EMS
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)
26b037fd
EMS
92 )
93 return postes.distinct()
105dd778
OL
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
4ba84959 104
105dd778
OL
105class ValeurPoint(object):
106
4ba84959
EMS
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 )
105dd778
OL
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)
0b0545bd 124
4ba84959 125
0b0545bd
OL
126class Employe(object):
127
4ba84959
EMS
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 )
0b0545bd
OL
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
4ba84959 144
0b0545bd
OL
145class Dossier(object):
146
4ba84959 147 def get_query(self, q, request):
05f7e241 148 return rh.Dossier.objects.ma_region_ou_service(request.user).filter(
3c927c12
BS
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 )
4ba84959 158 )
0b0545bd
OL
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)