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