1 # -*- encoding: utf-8 -*-
5 from django
.db
.models
import Q
6 from project
import groups
7 from project
.rh
import models
as rh
10 class Responsable(object):
13 def get_query(self
, q
, request
):
15 return rh
.Poste
.objects
.none()
19 Q(poste__nom__icontains
=q
) |
20 Q(poste__type_poste__nom__icontains
=q
) |
21 Q(employe__nom__icontains
=q
) |
22 Q(employe__prenom__icontains
=q
)
25 dossiers
= rh
.Dossier
.objects
.\
26 select_related('poste', 'poste__type_poste').\
30 postes
= list(set([d
.poste
for d
in dossiers
if q
in
31 unicode(d
.employe
).lower() or \
32 q
in d
.poste
.nom
.lower() or \
33 q
in d
.poste
.type_poste
.nom
.lower()]))
36 def format_result(self
, poste
):
38 filtre
= Q(poste
=poste
) & (
39 Q(poste__nom__icontains
=q
) |
Q(employe__nom__icontains
=q
) |
40 Q(employe__prenom__icontains
=q
)
42 dossiers
= rh
.Dossier
.objects
.actifs().filter(filtre
)
46 if len(dossiers
) == 1:
48 employe
= dossier
.employe
50 dossiers
= poste
.rh_dossiers
.all().order_by('-date_debut')
52 employe
= unicode(dossiers
[0].employe
)
55 return "[%s] %s (%s) (%s)" % (
56 poste
.implantation
.id, nom_poste
, poste
.id, employe
59 def format_item(self
, poste
):
61 the display of a currently selected object in the area below the
62 search box. html is OK
64 return self
.format_result(poste
)
66 def get_objects(self
, ids
):
68 given a list of ids, return the objects ordered as you would like
69 them on the admin page. this is for displaying the currently
70 selected items (in the case of a ManyToMany field)
72 return rh
.Poste
.objects
.filter(pk__in
=ids
)
75 class Dossier(object):
77 def get_query(self
, q
, request
):
78 employe
= groups
.get_employe_from_user(request
.user
)
79 prefixe_implantation
= 'poste__implantation'
82 (Q(poste__nom__icontains
=q
) |
83 Q(poste__type_poste__nom__icontains
=q
) |
84 Q(employe__nom__icontains
=q
) |
85 Q(employe__prenom__icontains
=q
))
89 prefixe_implantation
+ '__zone_administrative':
90 employe
.implantation
.zone_administrative
94 user_groupes
= [g
.name
for g
in request
.user
.groups
.all()]
95 if groups
.DRH_NIVEAU_1
in user_groupes
:
96 q_filtre
= q_recherche
98 q_filtre
= q_place
& q_recherche
99 return rh
.Dossier
.objects
.ma_region_ou_service(request
.user
).filter(q_filtre
).distinct()
101 def format_result(self
, dossier
):
102 return dossier
.__unicode__()
104 def format_item(self
, dossier
):
106 the display of a currently selected object in the area below the
107 search box. html is OK
109 return self
.format_result(dossier
)
111 def get_objects(self
, ids
):
113 given a list of ids, return the objects ordered as you would like
114 them on the admin page. this is for displaying the currently
115 selected items (in the case of a ManyToMany field)
117 return rh
.Dossier
.objects
.filter(pk__in
=ids
)
122 def get_query(self
, q
, request
):
123 employe
= groups
.get_employe_from_user(request
.user
)
124 prefixe_implantation
= 'poste__implantation'
127 (Q(poste__nom__icontains
=q
) |
128 Q(poste__type_poste__nom__icontains
=q
)) &
131 datetime
.date
.today() -
132 datetime
.timedelta(365)
136 # if groups.is_user_dans_services_centraux(request.user):
137 # q_place = Q(**{prefixe_implantation: employe.implantation})
140 # prefixe_implantation + '__zone_administrative':
141 # employe.implantation.zone_administrative
145 # user_groupes = [g.name for g in request.user.groups.all()]
146 # if groups.DRH_NIVEAU_1 in user_groupes or \
147 # groups.DRH_NIVEAU_2 in user_groupes:
148 # q_filtre = q_recherche
150 # q_filtre = q_place & q_recherche
152 q_filtre
= q_recherche
154 return rh
.Dossier
.objects
.ma_region_ou_service(request
.user
).filter(q_filtre
).order_by('-date_debut')
156 def format_result(self
, dossier
):
157 annee
= dossier
.date_debut
.year
158 if dossier
.date_fin
is not None:
159 annee
= dossier
.date_fin
.year
160 return u
"[%s] %s %s" % (
161 dossier
.poste
.implantation
, annee
, dossier
.poste
.nom
164 def format_item(self
, dossier
):
166 the display of a currently selected object in the area below the
167 search box. html is OK
169 return self
.format_result(dossier
)
171 def get_objects(self
, ids
):
173 given a list of ids, return the objects ordered as you would like
174 them on the admin page. this is for displaying the currently
175 selected items (in the case of a ManyToMany field)
177 return rh
.Dossier
.objects
.filter(pk__in
=ids
)