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(rh_dossiers__employe__nom__icontains
=q
) |
19 Q(rh_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
)
30 if len(dossiers
) == 1:
32 employe
= dossier
.employe
34 dossiers
= poste
.rh_dossiers
.all()
36 employe
= unicode(dossiers
[0].employe
)
39 return "[%s] %s (%s) (%s)" % (poste
.implantation
.id, nom_poste
, poste
.id, employe
)
41 def format_item(self
, poste
):
42 """ the display of a currently selected object in the area below the search box. html is OK """
43 return self
.format_result(poste
)
45 def get_objects(self
, ids
):
46 """ given a list of ids, return the objects ordered as you would like them on the admin page.
47 this is for displaying the currently selected items (in the case of a ManyToMany field)
49 return rh
.Poste
.objects
.filter(pk__in
=ids
)
51 class Dossier(object):
53 def get_query(self
,q
,request
):
54 employe
= get_employe_from_user(request
.user
)
55 prefixe_implantation
= 'poste__implantation'
57 q_recherche
= Q(poste__nom__icontains
=q
) | \
58 Q(poste__type_poste__nom__icontains
=q
) | \
59 Q(employe__nom__icontains
=q
) | \
60 Q(employe__prenom__icontains
=q
)
62 if is_user_dans_services_centraux(request
.user
):
63 q_place
= Q(**{ '%s' % prefixe_implantation
: employe
.implantation
})
65 q_place
= Q(**{ '%s__region' % prefixe_implantation
: employe
.implantation
.region
})
68 if grp_drh
in request
.user
.groups
.all():
69 q_filtre
= q_recherche
71 q_filtre
= q_place
& q_recherche
72 return rh
.Dossier
.objects
.filter(q_filtre
).distinct()
74 def format_result(self
, dossier
):
75 return dossier
.__unicode__()
77 def format_item(self
, dossier
):
78 """ the display of a currently selected object in the area below the search box. html is OK """
79 return self
.format_result(dossier
)
81 def get_objects(self
, ids
):
82 """ given a list of ids, return the objects ordered as you would like them on the admin page.
83 this is for displaying the currently selected items (in the case of a ManyToMany field)
85 return rh
.Dossier
.objects
.filter(pk__in
=ids
)
89 def get_query(self
,q
,request
):
90 employe
= get_employe_from_user(request
.user
)
91 prefixe_implantation
= 'poste__implantation'
93 q_recherche
= Q(poste__nom__icontains
=q
) |
Q(poste__type_poste__nom__icontains
=q
)
95 if is_user_dans_services_centraux(request
.user
):
96 q_place
= Q(**{ '%s' % prefixe_implantation
: employe
.implantation
})
98 q_place
= Q(**{ '%s__region' % prefixe_implantation
: employe
.implantation
.region
})
101 if grp_drh
in request
.user
.groups
.all():
102 q_filtre
= q_recherche
104 q_filtre
= q_place
& q_recherche
105 return rh
.Dossier
.objects
.filter(q_filtre
).order_by('-date_debut')
107 def format_result(self
, dossier
):
108 annee
= dossier
.date_debut
.year
109 if dossier
.date_fin
is not None:
110 annee
= dossier
.date_fin
.year
111 return u
"[%s] %s %s" % (dossier
.poste
.implantation
, annee
, dossier
.poste
.nom
)
113 def format_item(self
, dossier
):
114 """ the display of a currently selected object in the area below the search box. html is OK """
115 return self
.format_result(dossier
)
117 def get_objects(self
, ids
):
118 """ given a list of ids, return the objects ordered as you would like them on the admin page.
119 this is for displaying the currently selected items (in the case of a ManyToMany field)
121 return rh
.Dossier
.objects
.filter(pk__in
=ids
)