Commit | Line | Data |
---|---|---|
3121c13c OL |
1 | # -*- encoding: utf-8 -*- |
2 | ||
3121c13c | 3 | from django.db.models import Q |
b31ce2d7 EMS |
4 | |
5 | from project.dae.utils import \ | |
6 | get_employe_from_user, is_user_dans_services_centraux | |
7 | from project.dae.workflow import grp_drh | |
8 | from project.rh import models as rh | |
9 | ||
3121c13c OL |
10 | |
11 | class Responsable(object): | |
196e2d22 | 12 | q = "" |
b31ce2d7 EMS |
13 | |
14 | def get_query(self, q, request): | |
524ffcf0 OL |
15 | if len(q) < 4: |
16 | return rh.Poste.objects.none() | |
17 | ||
196e2d22 | 18 | self.q = q |
b31ce2d7 | 19 | postes = rh.Poste.objects.filter( |
3f5cbabe | 20 | Q(nom__icontains=q) | |
3121c13c | 21 | Q(type_poste__nom__icontains=q) | |
16b1454e OL |
22 | Q(rh_dossiers__employe__nom__icontains=q) | |
23 | Q(rh_dossiers__employe__prenom__icontains=q) | |
3121c13c | 24 | ).distinct() |
524ffcf0 | 25 | return postes |
3121c13c OL |
26 | |
27 | def format_result(self, poste): | |
196e2d22 | 28 | q = self.q |
b31ce2d7 EMS |
29 | filtre = Q(poste=poste) & ( |
30 | Q(poste__nom__icontains=q) | Q(employe__nom__icontains=q) | | |
31 | Q(employe__prenom__icontains=q) | |
32 | ) | |
196e2d22 | 33 | dossiers = rh.Dossier.objects.filter(filtre) |
b31ce2d7 | 34 | |
388547a4 | 35 | nom_poste = poste.nom |
b31ce2d7 | 36 | |
196e2d22 OL |
37 | if len(dossiers) == 1: |
38 | dossier = dossiers[0] | |
388547a4 | 39 | employe = dossier.employe |
8deddf9e | 40 | else: |
16b1454e | 41 | dossiers = poste.rh_dossiers.all() |
8deddf9e | 42 | if len(dossiers) > 0: |
8deddf9e | 43 | employe = unicode(dossiers[0].employe) |
388547a4 OL |
44 | else: |
45 | employe = "" | |
b31ce2d7 EMS |
46 | return "[%s] %s (%s) (%s)" % ( |
47 | poste.implantation.id, nom_poste, poste.id, employe | |
48 | ) | |
3121c13c OL |
49 | |
50 | def format_item(self, poste): | |
b31ce2d7 EMS |
51 | """ |
52 | the display of a currently selected object in the area below the | |
53 | search box. html is OK | |
54 | """ | |
3121c13c OL |
55 | return self.format_result(poste) |
56 | ||
57 | def get_objects(self, ids): | |
b31ce2d7 EMS |
58 | """ |
59 | given a list of ids, return the objects ordered as you would like | |
60 | them on the admin page. this is for displaying the currently | |
61 | selected items (in the case of a ManyToMany field) | |
3121c13c | 62 | """ |
03b395db OL |
63 | return rh.Poste.objects.filter(pk__in=ids) |
64 | ||
b31ce2d7 | 65 | |
03b395db OL |
66 | class Dossier(object): |
67 | ||
b31ce2d7 | 68 | def get_query(self, q, request): |
a4534f29 | 69 | employe = get_employe_from_user(request.user) |
09aa8374 | 70 | prefixe_implantation = 'poste__implantation' |
a4534f29 | 71 | |
09aa8374 OL |
72 | q_recherche = Q(poste__nom__icontains=q) | \ |
73 | Q(poste__type_poste__nom__icontains=q) | \ | |
a4534f29 | 74 | Q(employe__nom__icontains=q) | \ |
03b395db | 75 | Q(employe__prenom__icontains=q) |
a4534f29 | 76 | |
d8cfc3d5 | 77 | if is_user_dans_services_centraux(request.user): |
b31ce2d7 | 78 | q_place = Q(**{prefixe_implantation: employe.implantation}) |
a4534f29 | 79 | else: |
b31ce2d7 EMS |
80 | q_place = Q(**{ |
81 | prefixe_implantation + '__region': employe.implantation.region | |
82 | }) | |
a4534f29 OL |
83 | |
84 | if grp_drh in request.user.groups.all(): | |
85 | q_filtre = q_recherche | |
86 | else: | |
c0492570 | 87 | q_filtre = q_place & q_recherche |
a4534f29 | 88 | return rh.Dossier.objects.filter(q_filtre).distinct() |
03b395db OL |
89 | |
90 | def format_result(self, dossier): | |
91 | return dossier.__unicode__() | |
92 | ||
93 | def format_item(self, dossier): | |
b31ce2d7 EMS |
94 | """ |
95 | the display of a currently selected object in the area below the | |
96 | search box. html is OK | |
97 | """ | |
03b395db OL |
98 | return self.format_result(dossier) |
99 | ||
100 | def get_objects(self, ids): | |
b31ce2d7 EMS |
101 | """ |
102 | given a list of ids, return the objects ordered as you would like | |
103 | them on the admin page. this is for displaying the currently | |
104 | selected items (in the case of a ManyToMany field) | |
03b395db OL |
105 | """ |
106 | return rh.Dossier.objects.filter(pk__in=ids) | |
068d1462 | 107 | |
b31ce2d7 | 108 | |
068d1462 OL |
109 | class Poste(object): |
110 | ||
b31ce2d7 | 111 | def get_query(self, q, request): |
068d1462 | 112 | employe = get_employe_from_user(request.user) |
3f5cbabe | 113 | prefixe_implantation = 'poste__implantation' |
068d1462 | 114 | |
b31ce2d7 EMS |
115 | q_recherche = \ |
116 | Q(poste__nom__icontains=q) | \ | |
117 | Q(poste__type_poste__nom__icontains=q) | |
068d1462 OL |
118 | |
119 | if is_user_dans_services_centraux(request.user): | |
b31ce2d7 | 120 | q_place = Q(**{prefixe_implantation: employe.implantation}) |
068d1462 | 121 | else: |
b31ce2d7 EMS |
122 | q_place = Q(**{ |
123 | prefixe_implantation + '__region': employe.implantation.region | |
124 | }) | |
068d1462 OL |
125 | |
126 | if grp_drh in request.user.groups.all(): | |
127 | q_filtre = q_recherche | |
128 | else: | |
129 | q_filtre = q_place & q_recherche | |
e503e64d | 130 | return rh.Dossier.objects.filter(q_filtre).order_by('-date_debut') |
068d1462 OL |
131 | |
132 | def format_result(self, dossier): | |
e503e64d OL |
133 | annee = dossier.date_debut.year |
134 | if dossier.date_fin is not None: | |
135 | annee = dossier.date_fin.year | |
b31ce2d7 EMS |
136 | return u"[%s] %s %s" % ( |
137 | dossier.poste.implantation, annee, dossier.poste.nom | |
138 | ) | |
068d1462 OL |
139 | |
140 | def format_item(self, dossier): | |
b31ce2d7 EMS |
141 | """ |
142 | the display of a currently selected object in the area below the | |
143 | search box. html is OK | |
144 | """ | |
068d1462 OL |
145 | return self.format_result(dossier) |
146 | ||
147 | def get_objects(self, ids): | |
b31ce2d7 EMS |
148 | """ |
149 | given a list of ids, return the objects ordered as you would like | |
150 | them on the admin page. this is for displaying the currently | |
151 | selected items (in the case of a ManyToMany field) | |
068d1462 OL |
152 | """ |
153 | return rh.Dossier.objects.filter(pk__in=ids) |