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
)
27 dossiers
= poste
.poste1
.all().order_by("-id")
29 complement1
= dossiers
[0].complement1
30 employe
= unicode(dossiers
[0].employe
)
31 return "[%s] %s %s (%s) (%s)" % (poste
.implantation
.id, poste
.type_poste
.nom
, complement1
, poste
.id, employe
)
33 def format_item(self
, poste
):
34 """ the display of a currently selected object in the area below the search box. html is OK """
35 return self
.format_result(poste
)
37 def get_objects(self
, ids
):
38 """ given a list of ids, return the objects ordered as you would like them on the admin page.
39 this is for displaying the currently selected items (in the case of a ManyToMany field)
41 return rh
.Poste
.objects
.filter(pk__in
=ids
)
43 class Dossier(object):
45 def get_query(self
,q
,request
):
47 employe
= get_employe_from_user(request
.user
)
48 prefixe_implantation
= 'poste1__implantation'
50 q_recherche
= Q(complement1__icontains
=q
) | \
51 Q(poste1__type_poste__nom__icontains
=q
) | \
52 Q(employe__nom__icontains
=q
) | \
53 Q(employe__prenom__icontains
=q
)
55 if is_user_dans_services_centraux(request
.user
):
56 q_place
= Q(**{ '%s' % prefixe_implantation
: employe
.implantation
})
58 q_place
= Q(**{ '%s__region' % prefixe_implantation
: employe
.implantation
.region
})
61 if grp_drh
in request
.user
.groups
.all():
62 q_filtre
= q_recherche
64 q_filtre
= q_place
& q_recherche
65 return rh
.Dossier
.objects
.filter(q_filtre
).distinct()
67 def format_result(self
, dossier
):
68 return dossier
.__unicode__()
70 def format_item(self
, dossier
):
71 """ the display of a currently selected object in the area below the search box. html is OK """
72 return self
.format_result(dossier
)
74 def get_objects(self
, ids
):
75 """ given a list of ids, return the objects ordered as you would like them on the admin page.
76 this is for displaying the currently selected items (in the case of a ManyToMany field)
78 return rh
.Dossier
.objects
.filter(pk__in
=ids
)
82 def get_query(self
,q
,request
):
84 employe
= get_employe_from_user(request
.user
)
85 prefixe_implantation
= 'poste1__implantation'
87 q_recherche
= Q(complement1__icontains
=q
) |
Q(poste1__type_poste__nom__icontains
=q
)
89 if is_user_dans_services_centraux(request
.user
):
90 q_place
= Q(**{ '%s' % prefixe_implantation
: employe
.implantation
})
92 q_place
= Q(**{ '%s__region' % prefixe_implantation
: employe
.implantation
.region
})
95 if grp_drh
in request
.user
.groups
.all():
96 q_filtre
= q_recherche
98 q_filtre
= q_place
& q_recherche
99 return rh
.Dossier
.objects
.filter(q_filtre
).distinct()
101 def format_result(self
, dossier
):
102 return u
"[%s] %s" % (dossier
.poste1
.implantation
, dossier
.poste1
.type_poste
.nom
)
104 def format_item(self
, dossier
):
105 """ the display of a currently selected object in the area below the search box. html is OK """
106 return self
.format_result(dossier
)
108 def get_objects(self
, ids
):
109 """ given a list of ids, return the objects ordered as you would like them on the admin page.
110 this is for displaying the currently selected items (in the case of a ManyToMany field)
112 return rh
.Dossier
.objects
.filter(pk__in
=ids
)