workflow global supprimé (pertinent que pour DAE)
[auf_rh_dae.git] / project / rh / managers.py
1 # -*- encoding: utf-8 -*-
2
3 import datetime
4
5 from django.db import models
6 from django.db.models import Q
7
8 from auf.django.metadata.managers import NoDeleteManager
9
10 from project.utils import get_employe_from_user
11 from project.rh.groups import dae_groupes, \
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
23 class 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
72 if user.is_superuser:
73 liste = self.get_query_set().all()
74
75 return liste
76
77
78 class PosteManager(SecurityManager, NoDeleteManager):
79 """
80 Chargement de tous les objets FK existants sur chaque QuerySet.
81 """
82 prefixe_service = "service"
83 prefixe_implantation = "implantation__region"
84
85 def actifs(self):
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)
88
89 def ma_region_ou_service(self, user):
90 return super(PosteManager, self).ma_region_ou_service(user)
91
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()
107
108
109 class DossierManager(SecurityManager, NoDeleteManager):
110 prefixe_service = "poste__service"
111 prefixe_implantation = "poste__implantation__region"
112
113 def get_query_set(self):
114 fkeys = (
115 'poste',
116 'employe',
117 )
118 return super(DossierManager, self).get_query_set() \
119 .select_related(*fkeys).all()
120
121 def ma_region_ou_service(self, user):
122 return super(DossierManager, self).ma_region_ou_service(user)
123
124
125 class PosteComparaisonManager(SecurityManager):
126 use_for_related_fields = True
127 prefixe_implantation = "implantation__region"
128
129
130 class DossierComparaisonManager(SecurityManager):
131 use_for_related_fields = True
132 prefixe_implantation = "implantation__region"
133
134
135 class DeviseManager(NoDeleteManager):
136 pass
137
138 class ServiceManager(NoDeleteManager):
139 pass
140
141 class TypeRemunerationManager(NoDeleteManager):
142 pass