Commit | Line | Data |
---|---|---|
3121c13c OL |
1 | # -*- encoding: utf-8 -*- |
2 | ||
3121c13c | 3 | from django.db.models import Q |
09aa8374 | 4 | from rh 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( |
3f5cbabe | 16 | Q(nom__icontains=q) | |
3121c13c | 17 | Q(type_poste__nom__icontains=q) | |
3f5cbabe OL |
18 | Q(dossiers__employe__nom__icontains=q) | |
19 | Q(dossiers__employe__prenom__icontains=q) | |
3121c13c | 20 | ).distinct() |
524ffcf0 | 21 | return postes |
3121c13c OL |
22 | |
23 | def format_result(self, poste): | |
196e2d22 | 24 | q = self.q |
3f5cbabe | 25 | filtre = Q(poste=poste) & (Q(poste__nom__icontains=q) | Q(employe__nom__icontains=q) | Q(employe__prenom__icontains=q)) |
196e2d22 | 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] | |
3f5cbabe OL |
36 | if nom_poste == poste.nom: |
37 | return "[%s] %s (%s) (%s)" % (poste.implantation.id, nom_poste, poste.id, dossier.employe) | |
38 | else: | |
39 | return "[%s] %s %s (%s) (%s)" % (poste.implantation.id, nom_poste, poste.nom, poste.id, dossier.employe) | |
8deddf9e | 40 | else: |
3f5cbabe | 41 | dossiers = poste.dossiers.all() |
8deddf9e | 42 | if len(dossiers) > 0: |
3f5cbabe | 43 | complement1 = dossiers[0].poste.nom |
8deddf9e | 44 | employe = unicode(dossiers[0].employe) |
524ffcf0 | 45 | return "[%s] %s %s (%s) (%s)" % (poste.implantation.id, nom_poste, complement1, poste.id, employe) |
3121c13c OL |
46 | |
47 | def format_item(self, poste): | |
48 | """ the display of a currently selected object in the area below the search box. html is OK """ | |
49 | return self.format_result(poste) | |
50 | ||
51 | def get_objects(self, ids): | |
52 | """ given a list of ids, return the objects ordered as you would like them on the admin page. | |
53 | this is for displaying the currently selected items (in the case of a ManyToMany field) | |
54 | """ | |
03b395db OL |
55 | return rh.Poste.objects.filter(pk__in=ids) |
56 | ||
57 | class Dossier(object): | |
58 | ||
59 | def get_query(self,q,request): | |
a4534f29 OL |
60 | |
61 | employe = get_employe_from_user(request.user) | |
09aa8374 | 62 | prefixe_implantation = 'poste__implantation' |
a4534f29 | 63 | |
09aa8374 OL |
64 | q_recherche = Q(poste__nom__icontains=q) | \ |
65 | Q(poste__type_poste__nom__icontains=q) | \ | |
a4534f29 | 66 | Q(employe__nom__icontains=q) | \ |
03b395db | 67 | Q(employe__prenom__icontains=q) |
a4534f29 | 68 | |
d8cfc3d5 | 69 | if is_user_dans_services_centraux(request.user): |
a4534f29 OL |
70 | q_place = Q(**{ '%s' % prefixe_implantation : employe.implantation }) |
71 | else: | |
72 | q_place = Q(**{ '%s__region' % prefixe_implantation : employe.implantation.region }) | |
73 | ||
74 | ||
75 | if grp_drh in request.user.groups.all(): | |
76 | q_filtre = q_recherche | |
77 | else: | |
c0492570 | 78 | q_filtre = q_place & q_recherche |
a4534f29 | 79 | return rh.Dossier.objects.filter(q_filtre).distinct() |
03b395db OL |
80 | |
81 | def format_result(self, dossier): | |
82 | return dossier.__unicode__() | |
83 | ||
84 | def format_item(self, dossier): | |
85 | """ the display of a currently selected object in the area below the search box. html is OK """ | |
86 | return self.format_result(dossier) | |
87 | ||
88 | def get_objects(self, ids): | |
89 | """ given a list of ids, return the objects ordered as you would like them on the admin page. | |
90 | this is for displaying the currently selected items (in the case of a ManyToMany field) | |
91 | """ | |
92 | return rh.Dossier.objects.filter(pk__in=ids) | |
068d1462 OL |
93 | |
94 | class Poste(object): | |
95 | ||
96 | def get_query(self,q,request): | |
068d1462 | 97 | employe = get_employe_from_user(request.user) |
3f5cbabe | 98 | prefixe_implantation = 'poste__implantation' |
068d1462 | 99 | |
3f5cbabe | 100 | q_recherche = Q(poste__nom__icontains=q) | Q(poste__type_poste__nom__icontains=q) |
068d1462 OL |
101 | |
102 | if is_user_dans_services_centraux(request.user): | |
103 | q_place = Q(**{ '%s' % prefixe_implantation : employe.implantation }) | |
104 | else: | |
105 | q_place = Q(**{ '%s__region' % prefixe_implantation : employe.implantation.region }) | |
106 | ||
107 | ||
108 | if grp_drh in request.user.groups.all(): | |
109 | q_filtre = q_recherche | |
110 | else: | |
111 | q_filtre = q_place & q_recherche | |
112 | return rh.Dossier.objects.filter(q_filtre).distinct() | |
113 | ||
114 | def format_result(self, dossier): | |
3f5cbabe | 115 | return u"[%s] %s" % (dossier.poste.implantation, dossier.poste.type_poste.nom) |
068d1462 OL |
116 | |
117 | def format_item(self, dossier): | |
118 | """ the display of a currently selected object in the area below the search box. html is OK """ | |
119 | return self.format_result(dossier) | |
120 | ||
121 | def get_objects(self, ids): | |
122 | """ given a list of ids, return the objects ordered as you would like them on the admin page. | |
123 | this is for displaying the currently selected items (in the case of a ManyToMany field) | |
124 | """ | |
125 | return rh.Dossier.objects.filter(pk__in=ids) |