PEP8
[auf_rh_dae.git] / project / dae / managers.py
CommitLineData
f258e4e7
OL
1# -*- encoding: utf-8 -*-
2
f258e4e7 3from django.db.models import Q
b31ce2d7
EMS
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
515124ec 15
f258e4e7 16
3f5cbabe 17class TodoManagerMixin(object):
f258e4e7 18
515124ec
OL
19 def mes_choses_a_faire(self, user):
20 q = Q()
291bbfd9 21 employe = get_employe_from_user(user)
bb59cdf6 22 rien_a_faire = True
515124ec
OL
23 for g in user.groups.all():
24 etats = MAP_GROUPE_ETATS_A_FAIRE.get(g, ())
25 for etat in etats:
bb59cdf6 26 rien_a_faire = False
291bbfd9
EMS
27 q2 = Q(etat=etat)
28 if g == grp_service_utilisateurs:
29 q2 &= Q(**{self.prefixe_service: employe.service})
b31ce2d7
EMS
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 })
291bbfd9 36 q |= q2
515124ec 37
bb59cdf6
OL
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
515124ec
OL
43 return qs
44
b31ce2d7 45
3f5cbabe
OL
46class DossierManager(RHDossierManager, TodoManagerMixin):
47 pass
0b2edb6e 48
b31ce2d7 49
3f5cbabe
OL
50class PosteManager(RHPosteManager, TodoManagerMixin):
51 pass
b15bf543 52
b31ce2d7 53
3f5cbabe
OL
54class PosteComparaisonManager(RHPosteComparaisonManager, TodoManagerMixin):
55 pass
b15bf543 56
b31ce2d7 57
3f5cbabe
OL
58class DossierComparaisonManager(RHDossierComparaisonManager, TodoManagerMixin):
59 pass