[#3165] Remplacé les filtres et protection par région pour des filtres et protections...
[auf_rh_dae.git] / project / rh / catalogues.py
1 # -*- encoding: utf-8 -*-
2
3 from django.db.models import Q
4
5 from auf.django.references import models as ref
6
7 from project.groups import get_employe_from_user
8 from project.permissions import user_gere_obj_de_sa_region
9 from project.rh import models as rh
10
11
12 class Pays(object):
13 fk_key = "code"
14
15 def get_query(self, q, request):
16 pays = ref.Pays.objects.filter(
17 Q(nom__icontains=q) | Q(code__icontains=q)
18 )
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
31 class Implantation(object):
32
33 def get_query(self, q, request):
34 implantations = ref.Implantation.objects.filter(
35 Q(nom__icontains=q) | Q(nom_court__icontains=q) |
36 Q(nom_long__icontains=q) | Q(zone_administrative__nom__icontains=q)
37 )
38 if user_gere_obj_de_sa_region(request.user):
39 employe = get_employe_from_user(request.user)
40 implantations = implantations.filter(
41 zone_administrative=employe.implantation.zone_administrative
42 )
43 return implantations
44
45 def format_result(self, implantation):
46 statut = implantation.statut
47 if implantation.statut == 0:
48 statut = u"Jamais ouverte OU fermée"
49 if implantation.statut == 1:
50 statut = u"Ouverte"
51 if implantation.statut == 2:
52 statut = u"Fermée"
53 if implantation.statut == 3:
54 statut = u"Ouverte imminente"
55
56 return u"%s (%s) [%s]" % (implantation.nom, implantation.id, statut)
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
64
65 class TypePoste(object):
66
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 )
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
83
84 class Poste(object):
85
86 def get_query(self, q, request):
87 postes = rh.Poste.objects.ma_region_ou_service(request.user).filter(
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)
91 )
92 return postes.distinct()
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
103
104 class ValeurPoint(object):
105
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 )
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)
123
124
125 class Employe(object):
126
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 )
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
143
144 class Dossier(object):
145
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 )
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)