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