#3774
[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.FINANCE,
31 groups.HAUTE_DIRECTION,
32 groups.DRH_NIVEAU_1,
33 groups.DRH_NIVEAU_2,
34 ):
35 q2 &= Q(**{
36 self.prefixe_implantation:
37 employe.implantation.zone_administrative
38 })
39 q |= q2
40
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
46 return qs
47
48
49 class DossierManager(RHDossierManager, TodoManagerMixin):
50 pass
51
52
53 class PosteManager(RHPosteManager, TodoManagerMixin):
54 pass
55
56
57 class PosteComparaisonManager(RHPosteComparaisonManager, TodoManagerMixin):
58 pass
59
60
61 class DossierComparaisonManager(RHDossierComparaisonManager, TodoManagerMixin):
62 pass