import avec project.
[auf_rh_dae.git] / project / rh / managers.py
CommitLineData
3f5cbabe
OL
1# -*- encoding: utf-8 -*-
2
2a5259fe 3import datetime
75f0e87b 4
3f5cbabe
OL
5from django.db import models
6from django.db.models import Q
75f0e87b 7
a2c3ad52 8from auf.django.metadata.managers import NoDeleteManager
75f0e87b
DB
9
10from project.utils import get_employe_from_user
11from project.workflow import dae_groupes, \
3f5cbabe
OL
12 grp_administrateurs, \
13 grp_directeurs_bureau, \
14 grp_drh, \
15 grp_drh2, \
16 grp_accior, \
17 grp_abf, \
18 grp_haute_direction, \
19 grp_service_utilisateurs, \
20 grp_correspondants_rh
21
22
23class SecurityManager(models.Manager):
24
25 prefixe_service = None
26 prefixe_implantation = None
27
28 def ma_region_ou_service(self, user):
29 """
30 Filtrage des postes en fonction du user connecté (region / service)
31 On s'intéresse aussi au groupe auquel appartient le user car certains groupes
32 peuvent tout voir.
33 """
34 employe = get_employe_from_user(user)
35
36 ############################################
37 # TRAITEMENT NORMAL
38 ############################################
39 # REGION
40 q = Q(**{ self.prefixe_implantation : employe.implantation.region })
41
42 # SERVICE
43 if self.prefixe_service and grp_service_utilisateurs in user.groups.all():
44 q = q | Q(**{ self.prefixe_service : employe.service})
45
46 liste = self.get_query_set().filter(q)
47
48 ############################################
49 # TRAITEMENT ACCIOR
50 ############################################
51 if grp_accior in user.groups.all():
52 liste = self.get_query_set().all()
53
54 ############################################
55 # TRAITEMENT ABF
56 ############################################
57 if grp_abf in user.groups.all():
58 liste = self.get_query_set().all()
59
60 ############################################
61 # TRAITEMENT HAUTE DIRECTION
62 ############################################
63 if grp_haute_direction in user.groups.all():
64 liste = self.get_query_set().all()
65
66 ############################################
67 # TRAITEMENT DRH
68 ############################################
69 if grp_drh in user.groups.all() or grp_drh2 in user.groups.all():
70 liste = self.get_query_set().all()
71
9817fed5
OL
72 if user.is_superuser:
73 liste = self.get_query_set().all()
74
3f5cbabe
OL
75 return liste
76
77
a2c3ad52 78class PosteManager(SecurityManager, NoDeleteManager):
3f5cbabe
OL
79 """
80 Chargement de tous les objets FK existants sur chaque QuerySet.
81 """
82 prefixe_service = "service"
83 prefixe_implantation = "implantation__region"
84
f614ca5c 85 def actifs(self):
2a5259fe
OL
86 q_actif = Q(date_fin__gt=datetime.datetime.now()) | Q(date_fin__isnull=True)
87 return super(PosteManager, self).get_query_set().filter(q_actif)
f614ca5c 88
3f5cbabe 89 def ma_region_ou_service(self, user):
f614ca5c 90 return super(PosteManager, self).ma_region_ou_service(user)
3f5cbabe 91
0b0545bd
OL
92 def get_query_set(self):
93 fkeys = (
94 #'id_rh',
95 #'responsable',
96 #'implantation',
97 #'implantation.bureau_rattachement',
98 'type_poste',
99 #'service',
100 #'classement_min',
101 #'classement_max',
102 #'valeur_point_min',
103 #'valeur_point_max',
104 )
105 return super(PosteManager, self).get_query_set() \
106 .select_related(*fkeys).all()
3f5cbabe
OL
107
108
a2c3ad52 109class DossierManager(SecurityManager, NoDeleteManager):
3f5cbabe
OL
110 prefixe_service = "poste__service"
111 prefixe_implantation = "poste__implantation__region"
112
113 def get_query_set(self):
114 fkeys = (
115 'poste',
0b0545bd 116 'employe',
3f5cbabe
OL
117 )
118 return super(DossierManager, self).get_query_set() \
119 .select_related(*fkeys).all()
120
121 def ma_region_ou_service(self, user):
f614ca5c 122 return super(DossierManager, self).ma_region_ou_service(user)
3f5cbabe
OL
123
124
125class PosteComparaisonManager(SecurityManager):
126 use_for_related_fields = True
127 prefixe_implantation = "implantation__region"
128
4bdadf8b 129
3f5cbabe
OL
130class DossierComparaisonManager(SecurityManager):
131 use_for_related_fields = True
132 prefixe_implantation = "implantation__region"
4bdadf8b
OL
133
134
135class DeviseManager(NoDeleteManager):
7ba822a6 136 pass
4bdadf8b 137
7ba822a6
OL
138class ServiceManager(NoDeleteManager):
139 pass
140
141class TypeRemunerationManager(NoDeleteManager):
142 pass