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