1 # -*- encoding: utf-8 -*-
3 from django
.db
.models
import Q
4 from rh_v1
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
.filter(
13 Q(poste1__complement1__icontains
=q
) |
14 Q(type_poste__nom__icontains
=q
) |
15 Q(poste1__employe__nom__icontains
=q
) |
16 Q(poste1__employe__prenom__icontains
=q
)
19 def format_result(self
, poste
):
21 filtre
= Q(poste1
=poste
) & (Q(complement1__icontains
=q
) |
Q(employe__nom__icontains
=q
) |
Q(employe__prenom__icontains
=q
))
22 dossiers
= rh
.Dossier
.objects
.filter(filtre
)
23 if len(dossiers
) == 1:
25 return "[%s] %s %s (%s) (%s)" % (poste
.implantation
.id, poste
.type_poste
.nom
, dossier
.complement1
, poste
.id, dossier
.employe
)
26 return "[%s] %s %s" % (poste
.implantation
.id, poste
.type_poste
.nom
, poste
.id)
28 def format_item(self
, poste
):
29 """ the display of a currently selected object in the area below the search box. html is OK """
30 return self
.format_result(poste
)
32 def get_objects(self
, ids
):
33 """ given a list of ids, return the objects ordered as you would like them on the admin page.
34 this is for displaying the currently selected items (in the case of a ManyToMany field)
36 return rh
.Poste
.objects
.filter(pk__in
=ids
)
38 class Dossier(object):
40 def get_query(self
,q
,request
):
42 employe
= get_employe_from_user(request
.user
)
43 prefixe_implantation
= 'poste1__implantation'
45 q_recherche
= Q(complement1__icontains
=q
) | \
46 Q(poste1__type_poste__nom__icontains
=q
) | \
47 Q(employe__nom__icontains
=q
) | \
48 Q(employe__prenom__icontains
=q
)
50 if is_user_dans_services_centraux(request
.user
):
51 q_place
= Q(**{ '%s' % prefixe_implantation
: employe
.implantation
})
53 q_place
= Q(**{ '%s__region' % prefixe_implantation
: employe
.implantation
.region
})
56 if grp_drh
in request
.user
.groups
.all():
57 q_filtre
= q_recherche
59 q_filtre
= q_place
& q_recherche
60 return rh
.Dossier
.objects
.filter(q_filtre
).distinct()
62 def format_result(self
, dossier
):
63 return dossier
.__unicode__()
65 def format_item(self
, dossier
):
66 """ the display of a currently selected object in the area below the search box. html is OK """
67 return self
.format_result(dossier
)
69 def get_objects(self
, ids
):
70 """ given a list of ids, return the objects ordered as you would like them on the admin page.
71 this is for displaying the currently selected items (in the case of a ManyToMany field)
73 return rh
.Dossier
.objects
.filter(pk__in
=ids
)
77 def get_query(self
,q
,request
):
79 employe
= get_employe_from_user(request
.user
)
80 prefixe_implantation
= 'poste1__implantation'
82 q_recherche
= Q(complement1__icontains
=q
) |
Q(poste1__type_poste__nom__icontains
=q
)
84 if is_user_dans_services_centraux(request
.user
):
85 q_place
= Q(**{ '%s' % prefixe_implantation
: employe
.implantation
})
87 q_place
= Q(**{ '%s__region' % prefixe_implantation
: employe
.implantation
.region
})
90 if grp_drh
in request
.user
.groups
.all():
91 q_filtre
= q_recherche
93 q_filtre
= q_place
& q_recherche
94 return rh
.Dossier
.objects
.filter(q_filtre
).distinct()
96 def format_result(self
, dossier
):
97 return u
"[%s] %s" % (dossier
.poste1
.implantation
, dossier
.poste1
.type_poste
.nom
)
99 def format_item(self
, dossier
):
100 """ the display of a currently selected object in the area below the search box. html is OK """
101 return self
.format_result(dossier
)
103 def get_objects(self
, ids
):
104 """ given a list of ids, return the objects ordered as you would like them on the admin page.
105 this is for displaying the currently selected items (in the case of a ManyToMany field)
107 return rh
.Dossier
.objects
.filter(pk__in
=ids
)