import DAE
[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
47d7067b
OL
6from workflow import MAP_GROUPE_ETATS_A_FAIRE, DOSSIER_ETAT_FINALISE
7from workflow import grp_drh, \
5aaaef6b 8 grp_drh2, \
d8cfc3d5 9 grp_accior, \
9a62bc55 10 grp_abf, \
f258e4e7 11 grp_haute_direction, \
47d7067b 12 grp_service_utilisateurs
f258e4e7 13
3f5cbabe
OL
14from rh.managers import DossierManager as RHDossierManager
15from rh.managers import PosteManager as RHPosteManager
16from rh.managers import PosteComparaisonManager as RHPosteComparaisonManager
17from rh.managers import DossierComparaisonManager as RHDossierComparaisonManager
515124ec 18
f258e4e7 19
3f5cbabe 20class TodoManagerMixin(object):
f258e4e7 21
515124ec
OL
22 def mes_choses_a_faire(self, user):
23 q = Q()
291bbfd9 24 employe = get_employe_from_user(user)
bb59cdf6 25 rien_a_faire = True
515124ec
OL
26 for g in user.groups.all():
27 etats = MAP_GROUPE_ETATS_A_FAIRE.get(g, ())
28 for etat in etats:
bb59cdf6 29 rien_a_faire = False
291bbfd9
EMS
30 q2 = Q(etat=etat)
31 if g == grp_service_utilisateurs:
32 q2 &= Q(**{self.prefixe_service: employe.service})
5aaaef6b 33 elif g not in (grp_accior, grp_abf, grp_haute_direction, grp_drh, grp_drh2):
291bbfd9
EMS
34 q2 &= Q(**{self.prefixe_implantation: employe.implantation.region})
35 q |= q2
515124ec 36
bb59cdf6
OL
37 if rien_a_faire:
38 qs = self.ma_region_ou_service(user).none()
39 else:
40 qs = self.ma_region_ou_service(user).filter(q)
41
515124ec
OL
42 return qs
43
3f5cbabe
OL
44class DossierManager(RHDossierManager, TodoManagerMixin):
45 pass
0b2edb6e 46
3f5cbabe
OL
47class PosteManager(RHPosteManager, TodoManagerMixin):
48 pass
b15bf543 49
3f5cbabe
OL
50class PosteComparaisonManager(RHPosteComparaisonManager, TodoManagerMixin):
51 pass
b15bf543 52
3f5cbabe
OL
53class DossierComparaisonManager(RHDossierComparaisonManager, TodoManagerMixin):
54 pass
320d7584 55
47d7067b
OL
56class DossierFinaliseManager(models.Manager):
57 def get_query_set(self):
58 qs = super(DossierFinaliseManager,
59 self).get_query_set().filter(etat=DOSSIER_ETAT_FINALISE)
60 return qs
61
62