Routeur: Ajout temporaire des modules workflow et dae en écriture
[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 SecurityManager
12 from project.dae.workflow import MAP_GROUPE_ETATS_A_FAIRE
13
14
15 class ImplantationManager(SecurityManager):
16 use_for_related_fields = True
17 prefixe_implantation = "zone_administrative"
18
19 class TodoManagerMixin(object):
20
21 def mes_choses_a_faire(self, user):
22 q = Q()
23 employe = groups.get_employe_from_user(user)
24 rien_a_faire = True
25 for g in [g.name for g in user.groups.all()]:
26 etats = MAP_GROUPE_ETATS_A_FAIRE.get(g, ())
27 for etat in etats:
28 rien_a_faire = False
29 q2 = Q(etat=etat)
30 if g == groups.SERVICE_UTILISATEURS:
31 q2 &= Q(**{self.prefixe_service: employe.service})
32 elif g not in (
33 groups.ACCIOR,
34 groups.ABF,
35 groups.FINANCE,
36 groups.HAUTE_DIRECTION,
37 groups.DRH_NIVEAU_1,
38 groups.DRH_NIVEAU_2,
39 ):
40 q2 &= Q(**{
41 self.prefixe_implantation:
42 employe.implantation.zone_administrative
43 })
44 q |= q2
45
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
51 return qs
52
53
54 class DossierManager(RHDossierManager, TodoManagerMixin):
55 pass
56
57
58 class PosteManager(RHPosteManager, TodoManagerMixin):
59 pass
60
61
62 class PosteComparaisonManager(RHPosteComparaisonManager, TodoManagerMixin):
63 pass
64
65
66 class DossierComparaisonManager(RHDossierComparaisonManager, TodoManagerMixin):
67 pass