Fix django ajax selects
[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, DOSSIER_ETAT_FINALISE, \
7 POSTE_ETAT_FINALISE
8 from workflow import grp_drh, \
9 grp_drh2, \
10 grp_accior, \
11 grp_abf, \
12 grp_haute_direction, \
13 grp_service_utilisateurs
14
15 from rh.managers import DossierManager as RHDossierManager
16 from rh.managers import PosteManager as RHPosteManager
17 from rh.managers import PosteComparaisonManager as RHPosteComparaisonManager
18 from rh.managers import DossierComparaisonManager as RHDossierComparaisonManager
19
20
21 class TodoManagerMixin(object):
22
23 def mes_choses_a_faire(self, user):
24 q = Q()
25 employe = get_employe_from_user(user)
26 rien_a_faire = True
27 for g in user.groups.all():
28 etats = MAP_GROUPE_ETATS_A_FAIRE.get(g, ())
29 for etat in etats:
30 rien_a_faire = False
31 q2 = Q(etat=etat)
32 if g == grp_service_utilisateurs:
33 q2 &= Q(**{self.prefixe_service: employe.service})
34 elif g not in (grp_accior, grp_abf, grp_haute_direction, grp_drh, grp_drh2):
35 q2 &= Q(**{self.prefixe_implantation: employe.implantation.region})
36 q |= q2
37
38 if rien_a_faire:
39 qs = self.ma_region_ou_service(user).none()
40 else:
41 qs = self.ma_region_ou_service(user).filter(q)
42
43 return qs
44
45 class DossierManager(RHDossierManager, TodoManagerMixin):
46 pass
47
48 class PosteManager(RHPosteManager, TodoManagerMixin):
49 pass
50
51 class PosteComparaisonManager(RHPosteComparaisonManager, TodoManagerMixin):
52 pass
53
54 class DossierComparaisonManager(RHDossierComparaisonManager, TodoManagerMixin):
55 pass