PEP8
[auf_rh_dae.git] / project / dae / managers.py
... / ...
CommitLineData
1# -*- encoding: utf-8 -*-
2
3from django.db.models import Q
4
5from project.dae.utils import get_employe_from_user
6from project.dae.workflow import MAP_GROUPE_ETATS_A_FAIRE
7from project.dae.workflow import \
8 grp_drh, grp_drh2, grp_accior, \
9 grp_abf, grp_haute_direction, grp_service_utilisateurs
10from project.rh.managers import \
11 DossierManager as RHDossierManager, \
12 PosteManager as RHPosteManager, \
13 PosteComparaisonManager as RHPosteComparaisonManager, \
14 DossierComparaisonManager as RHDossierComparaisonManager
15
16
17class TodoManagerMixin(object):
18
19 def mes_choses_a_faire(self, user):
20 q = Q()
21 employe = get_employe_from_user(user)
22 rien_a_faire = True
23 for g in user.groups.all():
24 etats = MAP_GROUPE_ETATS_A_FAIRE.get(g, ())
25 for etat in etats:
26 rien_a_faire = False
27 q2 = Q(etat=etat)
28 if g == grp_service_utilisateurs:
29 q2 &= Q(**{self.prefixe_service: employe.service})
30 elif g not in (
31 grp_accior, grp_abf, grp_haute_direction, grp_drh, grp_drh2
32 ):
33 q2 &= Q(**{
34 self.prefixe_implantation: employe.implantation.region
35 })
36 q |= q2
37
38 if rien_a_faire:
39 qs = self.ma_region_ou_service(user).none()
40 else:
41 qs = self.ma_region_ou_service(user).filter(q)
42
43 return qs
44
45
46class DossierManager(RHDossierManager, TodoManagerMixin):
47 pass
48
49
50class PosteManager(RHPosteManager, TodoManagerMixin):
51 pass
52
53
54class PosteComparaisonManager(RHPosteComparaisonManager, TodoManagerMixin):
55 pass
56
57
58class DossierComparaisonManager(RHDossierComparaisonManager, TodoManagerMixin):
59 pass