securite recherche comparaison
[auf_rh_dae.git] / project / dae / catalogues.py
CommitLineData
3121c13c
OL
1# -*- encoding: utf-8 -*-
2
3121c13c 3from django.db.models import Q
a4534f29
OL
4from rh_v1 import models as rh
5from utils import get_employe_from_user, is_user_dans_service
6from workflow import grp_drh
3121c13c
OL
7
8class Responsable(object):
9
10 def get_query(self,q,request):
03b395db 11 return rh.Poste.objects.filter(
3121c13c
OL
12 Q(poste1__complement1__icontains=q) |
13 Q(type_poste__nom__icontains=q) |
14 Q(poste1__employe__nom__icontains=q) |
15 Q(poste1__employe__prenom__icontains=q)
16 ).distinct()
17
18 def format_result(self, poste):
19 dossiers = poste.poste1.all().order_by("-id")
20 complement1 = ""
21 employe = ""
22 if len(dossiers) > 0:
23 complement1 = dossiers[0].complement1
24 employe = unicode(dossiers[0].employe)
25 return "[%s] %s %s (%s) (%s)" % (poste.implantation.id, poste.type_poste.nom, complement1, poste.id, employe)
26
27 def format_item(self, poste):
28 """ the display of a currently selected object in the area below the search box. html is OK """
29 return self.format_result(poste)
30
31 def get_objects(self, ids):
32 """ given a list of ids, return the objects ordered as you would like them on the admin page.
33 this is for displaying the currently selected items (in the case of a ManyToMany field)
34 """
03b395db
OL
35 return rh.Poste.objects.filter(pk__in=ids)
36
37class Dossier(object):
38
39 def get_query(self,q,request):
a4534f29
OL
40
41 employe = get_employe_from_user(request.user)
42 prefixe_implantation = 'poste1__implantation'
43 print employe.implantation
44 print employe.implantation.region
45
46 q_recherche = Q(complement1__icontains=q) | \
47 Q(poste1__type_poste__nom__icontains=q) | \
48 Q(employe__nom__icontains=q) | \
03b395db 49 Q(employe__prenom__icontains=q)
a4534f29
OL
50
51 if is_user_dans_service(request.user):
52 q_place = Q(**{ '%s' % prefixe_implantation : employe.implantation })
53 else:
54 q_place = Q(**{ '%s__region' % prefixe_implantation : employe.implantation.region })
55
56
57 if grp_drh in request.user.groups.all():
58 q_filtre = q_recherche
59 else:
60 q_filtre = q_place & q_place
61
62 return rh.Dossier.objects.filter(q_filtre).distinct()
03b395db
OL
63
64 def format_result(self, dossier):
65 return dossier.__unicode__()
66
67 def format_item(self, dossier):
68 """ the display of a currently selected object in the area below the search box. html is OK """
69 return self.format_result(dossier)
70
71 def get_objects(self, ids):
72 """ given a list of ids, return the objects ordered as you would like them on the admin page.
73 this is for displaying the currently selected items (in the case of a ManyToMany field)
74 """
75 return rh.Dossier.objects.filter(pk__in=ids)