Accès à page perso via actions en haut à droite
[auf_rh_dae.git] / project / dae / catalogues.py
1 # -*- encoding: utf-8 -*-
2
3 from django.db.models import Q
4 from rh_v1 import models as rh
5 from utils import get_employe_from_user, is_user_dans_services_centraux
6 from workflow import grp_drh
7
8 class Responsable(object):
9
10 def get_query(self,q,request):
11 return rh.Poste.objects.filter(
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 """
35 return rh.Poste.objects.filter(pk__in=ids)
36
37 class Dossier(object):
38
39 def get_query(self,q,request):
40
41 employe = get_employe_from_user(request.user)
42 prefixe_implantation = 'poste1__implantation'
43
44 q_recherche = Q(complement1__icontains=q) | \
45 Q(poste1__type_poste__nom__icontains=q) | \
46 Q(employe__nom__icontains=q) | \
47 Q(employe__prenom__icontains=q)
48
49 if is_user_dans_services_centraux(request.user):
50 q_place = Q(**{ '%s' % prefixe_implantation : employe.implantation })
51 else:
52 q_place = Q(**{ '%s__region' % prefixe_implantation : employe.implantation.region })
53
54
55 if grp_drh in request.user.groups.all():
56 q_filtre = q_recherche
57 else:
58 q_filtre = q_place & q_recherche
59 return rh.Dossier.objects.filter(q_filtre).distinct()
60
61 def format_result(self, dossier):
62 return dossier.__unicode__()
63
64 def format_item(self, dossier):
65 """ the display of a currently selected object in the area below the search box. html is OK """
66 return self.format_result(dossier)
67
68 def get_objects(self, ids):
69 """ given a list of ids, return the objects ordered as you would like them on the admin page.
70 this is for displaying the currently selected items (in the case of a ManyToMany field)
71 """
72 return rh.Dossier.objects.filter(pk__in=ids)
73
74 class Poste(object):
75
76 def get_query(self,q,request):
77
78 employe = get_employe_from_user(request.user)
79 prefixe_implantation = 'poste1__implantation'
80
81 q_recherche = Q(complement1__icontains=q) | Q(poste1__type_poste__nom__icontains=q)
82
83 if is_user_dans_services_centraux(request.user):
84 q_place = Q(**{ '%s' % prefixe_implantation : employe.implantation })
85 else:
86 q_place = Q(**{ '%s__region' % prefixe_implantation : employe.implantation.region })
87
88
89 if grp_drh in request.user.groups.all():
90 q_filtre = q_recherche
91 else:
92 q_filtre = q_place & q_recherche
93 return rh.Dossier.objects.filter(q_filtre).distinct()
94
95 def format_result(self, dossier):
96 return u"[%s] %s" % (dossier.poste1.implantation, dossier.poste1.type_poste.nom)
97
98 def format_item(self, dossier):
99 """ the display of a currently selected object in the area below the search box. html is OK """
100 return self.format_result(dossier)
101
102 def get_objects(self, ids):
103 """ given a list of ids, return the objects ordered as you would like them on the admin page.
104 this is for displaying the currently selected items (in the case of a ManyToMany field)
105 """
106 return rh.Dossier.objects.filter(pk__in=ids)