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