Ajouté un manager et modele proxy pour obtenir une liste filtrée des Implantations
[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, \
1d521201
BS
10 DossierComparaisonManager as RHDossierComparaisonManager, \
11 SecurityManager
17c90428 12from project.dae.workflow import MAP_GROUPE_ETATS_A_FAIRE
515124ec 13
f258e4e7 14
1d521201
BS
15class ImplantationManager(SecurityManager):
16 use_for_related_fields = True
17 prefixe_implantation = "zone_administrative"
18
3f5cbabe 19class TodoManagerMixin(object):
f258e4e7 20
515124ec
OL
21 def mes_choses_a_faire(self, user):
22 q = Q()
3383b2d1 23 employe = groups.get_employe_from_user(user)
bb59cdf6 24 rien_a_faire = True
3383b2d1 25 for g in [g.name for g in user.groups.all()]:
515124ec
OL
26 etats = MAP_GROUPE_ETATS_A_FAIRE.get(g, ())
27 for etat in etats:
bb59cdf6 28 rien_a_faire = False
291bbfd9 29 q2 = Q(etat=etat)
3383b2d1 30 if g == groups.SERVICE_UTILISATEURS:
291bbfd9 31 q2 &= Q(**{self.prefixe_service: employe.service})
b31ce2d7 32 elif g not in (
3383b2d1
OL
33 groups.ACCIOR,
34 groups.ABF,
25f2c148 35 groups.FINANCE,
3383b2d1
OL
36 groups.HAUTE_DIRECTION,
37 groups.DRH_NIVEAU_1,
38 groups.DRH_NIVEAU_2,
b31ce2d7
EMS
39 ):
40 q2 &= Q(**{
b0cf30b8
EMS
41 self.prefixe_implantation:
42 employe.implantation.zone_administrative
b31ce2d7 43 })
291bbfd9 44 q |= q2
515124ec 45
bb59cdf6
OL
46 if rien_a_faire:
47 qs = self.ma_region_ou_service(user).none()
48 else:
49 qs = self.ma_region_ou_service(user).filter(q)
50
515124ec
OL
51 return qs
52
b31ce2d7 53
3f5cbabe
OL
54class DossierManager(RHDossierManager, TodoManagerMixin):
55 pass
0b2edb6e 56
b31ce2d7 57
3f5cbabe
OL
58class PosteManager(RHPosteManager, TodoManagerMixin):
59 pass
b15bf543 60
b31ce2d7 61
3f5cbabe
OL
62class PosteComparaisonManager(RHPosteComparaisonManager, TodoManagerMixin):
63 pass
b15bf543 64
b31ce2d7 65
3f5cbabe
OL
66class DossierComparaisonManager(RHDossierComparaisonManager, TodoManagerMixin):
67 pass