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