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