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_service
6 from workflow
import grp_drh
8 class Responsable(object):
10 def get_query(self
,q
,request
):
11 return rh
.Poste
.objects
.filter(
12 Q(poste1__complement1__icontains
=q
) |
13 Q(type_poste__nom__icontains
=q
) |
14 Q(poste1__employe__nom__icontains
=q
) |
15 Q(poste1__employe__prenom__icontains
=q
)
18 def format_result(self
, poste
):
19 dossiers
= poste
.poste1
.all().order_by("-id")
23 complement1
= dossiers
[0].complement1
24 employe
= unicode(dossiers
[0].employe
)
25 return "[%s] %s %s (%s) (%s)" % (poste
.implantation
.id, poste
.type_poste
.nom
, complement1
, poste
.id, employe
)
27 def format_item(self
, poste
):
28 """ the display of a currently selected object in the area below the search box. html is OK """
29 return self
.format_result(poste
)
31 def get_objects(self
, ids
):
32 """ given a list of ids, return the objects ordered as you would like them on the admin page.
33 this is for displaying the currently selected items (in the case of a ManyToMany field)
35 return rh
.Poste
.objects
.filter(pk__in
=ids
)
37 class Dossier(object):
39 def get_query(self
,q
,request
):
41 employe
= get_employe_from_user(request
.user
)
42 prefixe_implantation
= 'poste1__implantation'
43 print employe
.implantation
44 print employe
.implantation
.region
46 q_recherche
= Q(complement1__icontains
=q
) | \
47 Q(poste1__type_poste__nom__icontains
=q
) | \
48 Q(employe__nom__icontains
=q
) | \
49 Q(employe__prenom__icontains
=q
)
51 if is_user_dans_service(request
.user
):
52 q_place
= Q(**{ '%s' % prefixe_implantation
: employe
.implantation
})
54 q_place
= Q(**{ '%s__region' % prefixe_implantation
: employe
.implantation
.region
})
57 if grp_drh
in request
.user
.groups
.all():
58 q_filtre
= q_recherche
60 q_filtre
= q_place
& q_place
62 return rh
.Dossier
.objects
.filter(q_filtre
).distinct()
64 def format_result(self
, dossier
):
65 return dossier
.__unicode__()
67 def format_item(self
, dossier
):
68 """ the display of a currently selected object in the area below the search box. html is OK """
69 return self
.format_result(dossier
)
71 def get_objects(self
, ids
):
72 """ given a list of ids, return the objects ordered as you would like them on the admin page.
73 this is for displaying the currently selected items (in the case of a ManyToMany field)
75 return rh
.Dossier
.objects
.filter(pk__in
=ids
)