fix responsable ajax, le poste qui match, on retrouve le dossier de la personne si...
[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 q = ""
10 def get_query(self,q,request):
11 self.q = q
12 return rh.Poste.objects.filter(
13 Q(poste1__complement1__icontains=q) |
14 Q(type_poste__nom__icontains=q) |
15 Q(poste1__employe__nom__icontains=q) |
16 Q(poste1__employe__prenom__icontains=q)
17 ).distinct()
18
19 def format_result(self, poste):
20 q = self.q
21 filtre = Q(poste1=poste) & (Q(complement1__icontains=q) | Q(employe__nom__icontains=q) | Q(employe__prenom__icontains=q))
22 dossiers = rh.Dossier.objects.filter(filtre)
23 if len(dossiers) == 1:
24 dossier = dossiers[0]
25 return "[%s] %s %s (%s) (%s)" % (poste.implantation.id, poste.type_poste.nom, dossier.complement1, poste.id, dossier.employe)
26 else:
27 dossiers = poste.poste1.all().order_by("-id")
28 if len(dossiers) > 0:
29 complement1 = dossiers[0].complement1
30 employe = unicode(dossiers[0].employe)
31 return "[%s] %s %s (%s) (%s)" % (poste.implantation.id, poste.type_poste.nom, complement1, poste.id, employe)
32
33 def format_item(self, poste):
34 """ the display of a currently selected object in the area below the search box. html is OK """
35 return self.format_result(poste)
36
37 def get_objects(self, ids):
38 """ given a list of ids, return the objects ordered as you would like them on the admin page.
39 this is for displaying the currently selected items (in the case of a ManyToMany field)
40 """
41 return rh.Poste.objects.filter(pk__in=ids)
42
43 class Dossier(object):
44
45 def get_query(self,q,request):
46
47 employe = get_employe_from_user(request.user)
48 prefixe_implantation = 'poste1__implantation'
49
50 q_recherche = Q(complement1__icontains=q) | \
51 Q(poste1__type_poste__nom__icontains=q) | \
52 Q(employe__nom__icontains=q) | \
53 Q(employe__prenom__icontains=q)
54
55 if is_user_dans_services_centraux(request.user):
56 q_place = Q(**{ '%s' % prefixe_implantation : employe.implantation })
57 else:
58 q_place = Q(**{ '%s__region' % prefixe_implantation : employe.implantation.region })
59
60
61 if grp_drh in request.user.groups.all():
62 q_filtre = q_recherche
63 else:
64 q_filtre = q_place & q_recherche
65 return rh.Dossier.objects.filter(q_filtre).distinct()
66
67 def format_result(self, dossier):
68 return dossier.__unicode__()
69
70 def format_item(self, dossier):
71 """ the display of a currently selected object in the area below the search box. html is OK """
72 return self.format_result(dossier)
73
74 def get_objects(self, ids):
75 """ given a list of ids, return the objects ordered as you would like them on the admin page.
76 this is for displaying the currently selected items (in the case of a ManyToMany field)
77 """
78 return rh.Dossier.objects.filter(pk__in=ids)
79
80 class Poste(object):
81
82 def get_query(self,q,request):
83
84 employe = get_employe_from_user(request.user)
85 prefixe_implantation = 'poste1__implantation'
86
87 q_recherche = Q(complement1__icontains=q) | Q(poste1__type_poste__nom__icontains=q)
88
89 if is_user_dans_services_centraux(request.user):
90 q_place = Q(**{ '%s' % prefixe_implantation : employe.implantation })
91 else:
92 q_place = Q(**{ '%s__region' % prefixe_implantation : employe.implantation.region })
93
94
95 if grp_drh in request.user.groups.all():
96 q_filtre = q_recherche
97 else:
98 q_filtre = q_place & q_recherche
99 return rh.Dossier.objects.filter(q_filtre).distinct()
100
101 def format_result(self, dossier):
102 return u"[%s] %s" % (dossier.poste1.implantation, dossier.poste1.type_poste.nom)
103
104 def format_item(self, dossier):
105 """ the display of a currently selected object in the area below the search box. html is OK """
106 return self.format_result(dossier)
107
108 def get_objects(self, ids):
109 """ given a list of ids, return the objects ordered as you would like them on the admin page.
110 this is for displaying the currently selected items (in the case of a ManyToMany field)
111 """
112 return rh.Dossier.objects.filter(pk__in=ids)