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