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