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