[#3165] Remplacé les filtres et protection par région pour des filtres et protections...
[auf_rh_dae.git] / project / dae / managers.py
CommitLineData
f258e4e7
OL
1# -*- encoding: utf-8 -*-
2
f258e4e7 3from django.db.models import Q
b31ce2d7 4
3383b2d1 5from project import groups
b31ce2d7
EMS
6from project.rh.managers import \
7 DossierManager as RHDossierManager, \
8 PosteManager as RHPosteManager, \
9 PosteComparaisonManager as RHPosteComparaisonManager, \
10 DossierComparaisonManager as RHDossierComparaisonManager
17c90428 11from project.dae.workflow import MAP_GROUPE_ETATS_A_FAIRE
515124ec 12
f258e4e7 13
3f5cbabe 14class TodoManagerMixin(object):
f258e4e7 15
515124ec
OL
16 def mes_choses_a_faire(self, user):
17 q = Q()
3383b2d1 18 employe = groups.get_employe_from_user(user)
bb59cdf6 19 rien_a_faire = True
3383b2d1 20 for g in [g.name for g in user.groups.all()]:
515124ec
OL
21 etats = MAP_GROUPE_ETATS_A_FAIRE.get(g, ())
22 for etat in etats:
bb59cdf6 23 rien_a_faire = False
291bbfd9 24 q2 = Q(etat=etat)
3383b2d1 25 if g == groups.SERVICE_UTILISATEURS:
291bbfd9 26 q2 &= Q(**{self.prefixe_service: employe.service})
b31ce2d7 27 elif g not in (
3383b2d1
OL
28 groups.ACCIOR,
29 groups.ABF,
30 groups.HAUTE_DIRECTION,
31 groups.DRH_NIVEAU_1,
32 groups.DRH_NIVEAU_2,
b31ce2d7
EMS
33 ):
34 q2 &= Q(**{
b0cf30b8
EMS
35 self.prefixe_implantation:
36 employe.implantation.zone_administrative
b31ce2d7 37 })
291bbfd9 38 q |= q2
515124ec 39
bb59cdf6
OL
40 if rien_a_faire:
41 qs = self.ma_region_ou_service(user).none()
42 else:
43 qs = self.ma_region_ou_service(user).filter(q)
44
515124ec
OL
45 return qs
46
b31ce2d7 47
3f5cbabe
OL
48class DossierManager(RHDossierManager, TodoManagerMixin):
49 pass
0b2edb6e 50
b31ce2d7 51
3f5cbabe
OL
52class PosteManager(RHPosteManager, TodoManagerMixin):
53 pass
b15bf543 54
b31ce2d7 55
3f5cbabe
OL
56class PosteComparaisonManager(RHPosteComparaisonManager, TodoManagerMixin):
57 pass
b15bf543 58
b31ce2d7 59
3f5cbabe
OL
60class DossierComparaisonManager(RHDossierComparaisonManager, TodoManagerMixin):
61 pass