1 # -*- encoding: utf-8 -*-
3 from django
.db
.models
import Q
5 from auf
.django
.references
import models
as ref
7 from project
.groups
import get_employe_from_user
8 from project
.permissions
import user_gere_obj_de_sa_region
9 from project
.rh
import models
as rh
15 def get_query(self
, q
, request
):
16 pays
= ref
.Pays
.objects
.filter(
17 Q(nom__icontains
=q
) |
Q(code__icontains
=q
)
21 def format_result(self
, pays
):
24 def format_item(self
, pays
):
25 return self
.format_result(pays
)
27 def get_objects(self
, ids
):
28 return ref
.Pays
.objects
.filter(code__in
=ids
)
31 class Implantation(object):
33 def get_query(self
, q
, request
):
34 implantations
= ref
.Implantation
.objects
.filter(
35 Q(nom__icontains
=q
) |
Q(nom_court__icontains
=q
) |
36 Q(nom_long__icontains
=q
) |
Q(zone_administrative__nom__icontains
=q
)
38 if user_gere_obj_de_sa_region(request
.user
):
39 employe
= get_employe_from_user(request
.user
)
40 implantations
= implantations
.filter(
41 zone_administrative
=employe
.implantation
.zone_administrative
45 def format_result(self
, implantation
):
46 statut
= implantation
.statut
47 if implantation
.statut
== 0:
48 statut
= u
"Jamais ouverte OU fermée"
49 if implantation
.statut
== 1:
51 if implantation
.statut
== 2:
53 if implantation
.statut
== 3:
54 statut
= u
"Ouverte imminente"
56 return u
"%s (%s) [%s]" % (implantation
.nom
, implantation
.id, statut
)
58 def format_item(self
, implantation
):
59 return self
.format_result(implantation
)
61 def get_objects(self
, ids
):
62 return ref
.Implantation
.objects
.filter(id__in
=ids
)
65 class TypePoste(object):
67 def get_query(self
, q
, request
):
68 typepostes
= rh
.TypePoste
.objects
.filter(
69 Q(nom__icontains
=q
) |
Q(nom_feminin__icontains
=q
) |
70 Q(categorie_emploi__nom__icontains
=q
)
74 def format_result(self
, typeposte
):
75 return unicode(typeposte
)
77 def format_item(self
, typeposte
):
78 return self
.format_result(typeposte
)
80 def get_objects(self
, ids
):
81 return rh
.TypePoste
.objects
.filter(id__in
=ids
)
86 def get_query(self
, q
, request
):
87 postes
= rh
.Poste
.objects
.ma_region_ou_service(request
.user
).filter(
88 Q(nom__icontains
=q
) |
Q(type_poste__nom__icontains
=q
) |
89 Q(rh_dossiers__employe__nom__icontains
=q
) |
90 Q(rh_dossiers__employe__prenom__icontains
=q
)
92 return postes
.distinct()
94 def format_result(self
, poste
):
97 def format_item(self
, poste
):
98 return self
.format_result(poste
)
100 def get_objects(self
, ids
):
101 return rh
.Poste
.objects
.filter(id__in
=ids
)
104 class ValeurPoint(object):
106 def get_query(self
, q
, request
):
107 points
= rh
.ValeurPoint
.objects \
108 .select_related('devise', 'implantation') \
110 Q(devise__code__icontains
=q
) |
111 Q(implantation__nom__icontains
=q
)
115 def format_result(self
, point
):
116 return unicode(point
)
118 def format_item(self
, point
):
119 return self
.format_result(point
)
121 def get_objects(self
, ids
):
122 return rh
.ValeurPoint
.objects
.filter(id__in
=ids
)
125 class Employe(object):
127 def get_query(self
, q
, request
):
128 employes
= rh
.Employe
.objects
.filter(
129 Q(nom__icontains
=q
) |
Q(prenom__icontains
=q
) |
130 Q(nom_affichage__icontains
=q
)
134 def format_result(self
, employe
):
135 return unicode(employe
)
137 def format_item(self
, employe
):
138 return self
.format_result(employe
)
140 def get_objects(self
, ids
):
141 return rh
.Employe
.objects
.filter(id__in
=ids
)
144 class Dossier(object):
146 def get_query(self
, q
, request
):
147 dossiers
= rh
.Dossier
.objects
.filter(
148 Q(poste__nom
=q
) |
Q(poste__type_poste__nom
=q
) |
149 Q(employe__nom__icontains
=q
) |
Q(employe__prenom__icontains
=q
) |
150 Q(employe__nom_affichage__icontains
=q
)
154 def format_result(self
, dossier
):
155 return unicode(dossier
)
157 def format_item(self
, dossier
):
158 return self
.format_result(dossier
)
160 def get_objects(self
, ids
):
161 return rh
.Dossier
.objects
.filter(id__in
=ids
)