1 # -*- encoding: utf-8 -*-
3 from django
.db
.models
import Q
5 from project
.groups
import \
6 get_employe_from_user
, is_user_dans_services_centraux
7 from project
.rh
import models
as rh
9 from project
.dae
.workflow
import grp_drh
12 class Responsable(object):
15 def get_query(self
, q
, request
):
17 return rh
.Poste
.objects
.none()
20 postes
= rh
.Poste
.objects
.filter(
22 Q(type_poste__nom__icontains
=q
) |
23 Q(rh_dossiers__employe__nom__icontains
=q
) |
24 Q(rh_dossiers__employe__prenom__icontains
=q
)
28 def format_result(self
, poste
):
30 filtre
= Q(poste
=poste
) & (
31 Q(poste__nom__icontains
=q
) |
Q(employe__nom__icontains
=q
) |
32 Q(employe__prenom__icontains
=q
)
34 dossiers
= rh
.Dossier
.objects
.filter(filtre
)
38 if len(dossiers
) == 1:
40 employe
= dossier
.employe
42 dossiers
= poste
.rh_dossiers
.all()
44 employe
= unicode(dossiers
[0].employe
)
47 return "[%s] %s (%s) (%s)" % (
48 poste
.implantation
.id, nom_poste
, poste
.id, employe
51 def format_item(self
, poste
):
53 the display of a currently selected object in the area below the
54 search box. html is OK
56 return self
.format_result(poste
)
58 def get_objects(self
, ids
):
60 given a list of ids, return the objects ordered as you would like
61 them on the admin page. this is for displaying the currently
62 selected items (in the case of a ManyToMany field)
64 return rh
.Poste
.objects
.filter(pk__in
=ids
)
67 class Dossier(object):
69 def get_query(self
, q
, request
):
70 employe
= get_employe_from_user(request
.user
)
71 prefixe_implantation
= 'poste__implantation'
73 q_recherche
= Q(poste__nom__icontains
=q
) | \
74 Q(poste__type_poste__nom__icontains
=q
) | \
75 Q(employe__nom__icontains
=q
) | \
76 Q(employe__prenom__icontains
=q
)
78 if is_user_dans_services_centraux(request
.user
):
79 q_place
= Q(**{prefixe_implantation
: employe
.implantation
})
82 prefixe_implantation
+ '__region': employe
.implantation
.region
85 if grp_drh
in request
.user
.groups
.all():
86 q_filtre
= q_recherche
88 q_filtre
= q_place
& q_recherche
89 return rh
.Dossier
.objects
.filter(q_filtre
).distinct()
91 def format_result(self
, dossier
):
92 return dossier
.__unicode__()
94 def format_item(self
, dossier
):
96 the display of a currently selected object in the area below the
97 search box. html is OK
99 return self
.format_result(dossier
)
101 def get_objects(self
, ids
):
103 given a list of ids, return the objects ordered as you would like
104 them on the admin page. this is for displaying the currently
105 selected items (in the case of a ManyToMany field)
107 return rh
.Dossier
.objects
.filter(pk__in
=ids
)
112 def get_query(self
, q
, request
):
113 employe
= get_employe_from_user(request
.user
)
114 prefixe_implantation
= 'poste__implantation'
117 Q(poste__nom__icontains
=q
) | \
118 Q(poste__type_poste__nom__icontains
=q
)
120 if is_user_dans_services_centraux(request
.user
):
121 q_place
= Q(**{prefixe_implantation
: employe
.implantation
})
124 prefixe_implantation
+ '__region': employe
.implantation
.region
127 if grp_drh
in request
.user
.groups
.all():
128 q_filtre
= q_recherche
130 q_filtre
= q_place
& q_recherche
131 return rh
.Dossier
.objects
.filter(q_filtre
).order_by('-date_debut')
133 def format_result(self
, dossier
):
134 annee
= dossier
.date_debut
.year
135 if dossier
.date_fin
is not None:
136 annee
= dossier
.date_fin
.year
137 return u
"[%s] %s %s" % (
138 dossier
.poste
.implantation
, annee
, dossier
.poste
.nom
141 def format_item(self
, dossier
):
143 the display of a currently selected object in the area below the
144 search box. html is OK
146 return self
.format_result(dossier
)
148 def get_objects(self
, ids
):
150 given a list of ids, return the objects ordered as you would like
151 them on the admin page. this is for displaying the currently
152 selected items (in the case of a ManyToMany field)
154 return rh
.Dossier
.objects
.filter(pk__in
=ids
)