Commit | Line | Data |
---|---|---|
3121c13c OL |
1 | # -*- encoding: utf-8 -*- |
2 | ||
3121c13c | 3 | from django.db.models import Q |
a4534f29 | 4 | from rh_v1 import models as rh |
d8cfc3d5 | 5 | from utils import get_employe_from_user, is_user_dans_services_centraux |
a4534f29 | 6 | from workflow import grp_drh |
3121c13c OL |
7 | |
8 | class Responsable(object): | |
196e2d22 | 9 | q = "" |
3121c13c | 10 | def get_query(self,q,request): |
196e2d22 | 11 | self.q = q |
03b395db | 12 | return rh.Poste.objects.filter( |
3121c13c OL |
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): | |
196e2d22 OL |
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) | |
3121c13c OL |
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 | """ | |
03b395db OL |
36 | return rh.Poste.objects.filter(pk__in=ids) |
37 | ||
38 | class Dossier(object): | |
39 | ||
40 | def get_query(self,q,request): | |
a4534f29 OL |
41 | |
42 | employe = get_employe_from_user(request.user) | |
43 | prefixe_implantation = 'poste1__implantation' | |
a4534f29 OL |
44 | |
45 | q_recherche = Q(complement1__icontains=q) | \ | |
46 | Q(poste1__type_poste__nom__icontains=q) | \ | |
47 | Q(employe__nom__icontains=q) | \ | |
03b395db | 48 | Q(employe__prenom__icontains=q) |
a4534f29 | 49 | |
d8cfc3d5 | 50 | if is_user_dans_services_centraux(request.user): |
a4534f29 OL |
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: | |
c0492570 | 59 | q_filtre = q_place & q_recherche |
a4534f29 | 60 | return rh.Dossier.objects.filter(q_filtre).distinct() |
03b395db OL |
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) | |
068d1462 OL |
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) |