1 # -*- encoding: utf-8 -*-
3 from django
.db
.models
import Q
4 from rh
import models
as rh
5 from utils
import get_employe_from_user
, is_user_dans_services_centraux
6 from workflow
import grp_drh
8 class Responsable(object):
10 def get_query(self
,q
,request
):
12 return rh
.Poste
.objects
.none()
15 postes
= rh
.Poste
.objects
.filter(
17 Q(type_poste__nom__icontains
=q
) |
18 Q(dossiers__employe__nom__icontains
=q
) |
19 Q(dossiers__employe__prenom__icontains
=q
)
23 def format_result(self
, poste
):
25 filtre
= Q(poste
=poste
) & (Q(poste__nom__icontains
=q
) |
Q(employe__nom__icontains
=q
) |
Q(employe__prenom__icontains
=q
))
26 dossiers
= rh
.Dossier
.objects
.filter(filtre
)
28 # certains postes ont un id de type de poste qui n'existe pas
30 nom_poste
= poste
.type_poste
.nom
34 if len(dossiers
) == 1:
36 if nom_poste
== poste
.nom
:
37 return "[%s] %s (%s) (%s)" % (poste
.implantation
.id, nom_poste
, poste
.id, dossier
.employe
)
39 return "[%s] %s %s (%s) (%s)" % (poste
.implantation
.id, nom_poste
, poste
.nom
, poste
.id, dossier
.employe
)
41 dossiers
= poste
.dossiers
.all()
43 complement1
= dossiers
[0].poste
.nom
44 employe
= unicode(dossiers
[0].employe
)
45 return "[%s] %s %s (%s) (%s)" % (poste
.implantation
.id, nom_poste
, complement1
, poste
.id, employe
)
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
)
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)
55 return rh
.Poste
.objects
.filter(pk__in
=ids
)
57 class Dossier(object):
59 def get_query(self
,q
,request
):
61 employe
= get_employe_from_user(request
.user
)
62 prefixe_implantation
= 'poste__implantation'
64 q_recherche
= Q(poste__nom__icontains
=q
) | \
65 Q(poste__type_poste__nom__icontains
=q
) | \
66 Q(employe__nom__icontains
=q
) | \
67 Q(employe__prenom__icontains
=q
)
69 if is_user_dans_services_centraux(request
.user
):
70 q_place
= Q(**{ '%s' % prefixe_implantation
: employe
.implantation
})
72 q_place
= Q(**{ '%s__region' % prefixe_implantation
: employe
.implantation
.region
})
75 if grp_drh
in request
.user
.groups
.all():
76 q_filtre
= q_recherche
78 q_filtre
= q_place
& q_recherche
79 return rh
.Dossier
.objects
.filter(q_filtre
).distinct()
81 def format_result(self
, dossier
):
82 return dossier
.__unicode__()
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
)
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)
92 return rh
.Dossier
.objects
.filter(pk__in
=ids
)
96 def get_query(self
,q
,request
):
97 employe
= get_employe_from_user(request
.user
)
98 prefixe_implantation
= 'poste__implantation'
100 q_recherche
= Q(poste__nom__icontains
=q
) |
Q(poste__type_poste__nom__icontains
=q
)
102 if is_user_dans_services_centraux(request
.user
):
103 q_place
= Q(**{ '%s' % prefixe_implantation
: employe
.implantation
})
105 q_place
= Q(**{ '%s__region' % prefixe_implantation
: employe
.implantation
.region
})
108 if grp_drh
in request
.user
.groups
.all():
109 q_filtre
= q_recherche
111 q_filtre
= q_place
& q_recherche
112 return rh
.Dossier
.objects
.filter(q_filtre
).distinct()
114 def format_result(self
, dossier
):
115 return u
"[%s] %s" % (dossier
.poste
.implantation
, dossier
.poste
.type_poste
.nom
)
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
)
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)
125 return rh
.Dossier
.objects
.filter(pk__in
=ids
)