#3774
[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,
25f2c148 30 groups.FINANCE,
3383b2d1
OL
31 groups.HAUTE_DIRECTION,
32 groups.DRH_NIVEAU_1,
33 groups.DRH_NIVEAU_2,
b31ce2d7
EMS
34 ):
35 q2 &= Q(**{
b0cf30b8
EMS
36 self.prefixe_implantation:
37 employe.implantation.zone_administrative
b31ce2d7 38 })
291bbfd9 39 q |= q2
515124ec 40
bb59cdf6
OL
41 if rien_a_faire:
42 qs = self.ma_region_ou_service(user).none()
43 else:
44 qs = self.ma_region_ou_service(user).filter(q)
45
515124ec
OL
46 return qs
47
b31ce2d7 48
3f5cbabe
OL
49class DossierManager(RHDossierManager, TodoManagerMixin):
50 pass
0b2edb6e 51
b31ce2d7 52
3f5cbabe
OL
53class PosteManager(RHPosteManager, TodoManagerMixin):
54 pass
b15bf543 55
b31ce2d7 56
3f5cbabe
OL
57class PosteComparaisonManager(RHPosteComparaisonManager, TodoManagerMixin):
58 pass
b15bf543 59
b31ce2d7 60
3f5cbabe
OL
61class DossierComparaisonManager(RHDossierComparaisonManager, TodoManagerMixin):
62 pass