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