poste import + liens dans RH
[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
a47ed016
OL
6from workflow import MAP_GROUPE_ETATS_A_FAIRE, DOSSIER_ETAT_FINALISE, \
7 POSTE_ETAT_FINALISE
47d7067b 8from workflow import grp_drh, \
5aaaef6b 9 grp_drh2, \
d8cfc3d5 10 grp_accior, \
9a62bc55 11 grp_abf, \
f258e4e7 12 grp_haute_direction, \
47d7067b 13 grp_service_utilisateurs
f258e4e7 14
3f5cbabe
OL
15from rh.managers import DossierManager as RHDossierManager
16from rh.managers import PosteManager as RHPosteManager
17from rh.managers import PosteComparaisonManager as RHPosteComparaisonManager
18from rh.managers import DossierComparaisonManager as RHDossierComparaisonManager
515124ec 19
f258e4e7 20
3f5cbabe 21class TodoManagerMixin(object):
f258e4e7 22
515124ec
OL
23 def mes_choses_a_faire(self, user):
24 q = Q()
291bbfd9 25 employe = get_employe_from_user(user)
bb59cdf6 26 rien_a_faire = True
515124ec
OL
27 for g in user.groups.all():
28 etats = MAP_GROUPE_ETATS_A_FAIRE.get(g, ())
29 for etat in etats:
bb59cdf6 30 rien_a_faire = False
291bbfd9
EMS
31 q2 = Q(etat=etat)
32 if g == grp_service_utilisateurs:
33 q2 &= Q(**{self.prefixe_service: employe.service})
5aaaef6b 34 elif g not in (grp_accior, grp_abf, grp_haute_direction, grp_drh, grp_drh2):
291bbfd9
EMS
35 q2 &= Q(**{self.prefixe_implantation: employe.implantation.region})
36 q |= q2
515124ec 37
bb59cdf6
OL
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
515124ec
OL
43 return qs
44
3f5cbabe
OL
45class DossierManager(RHDossierManager, TodoManagerMixin):
46 pass
0b2edb6e 47
3f5cbabe
OL
48class PosteManager(RHPosteManager, TodoManagerMixin):
49 pass
b15bf543 50
3f5cbabe
OL
51class PosteComparaisonManager(RHPosteComparaisonManager, TodoManagerMixin):
52 pass
b15bf543 53
3f5cbabe
OL
54class DossierComparaisonManager(RHDossierComparaisonManager, TodoManagerMixin):
55 pass
320d7584 56
47d7067b 57class DossierFinaliseManager(models.Manager):
59c67b87
OL
58 """
59 Dossiers finalisés, qui ne sont pas encore importés
60 """
47d7067b 61 def get_query_set(self):
59c67b87
OL
62 from dae.models import ImportDossier
63 dae_importees = [str(i.dae_id) for i in ImportDossier.objects.all()]
a47ed016
OL
64 qs = super(DossierFinaliseManager, self).get_query_set().filter(etat=DOSSIER_ETAT_FINALISE,)
65 if len(dae_importees) > 0:
66 qs = qs.extra(where=['id NOT IN (%s)' % ", ".join(dae_importees)])
67 return qs
68
69
70class PosteFinaliseManager(models.Manager):
71 """
72 Dossiers finalisés, qui ne sont pas encore importés
73 """
74 def get_query_set(self):
75 from dae.models import ImportPoste
76 dae_importees = [str(i.dae_id) for i in ImportPoste.objects.all()]
77
78 qs = super(PosteFinaliseManager, self).get_query_set().filter(etat=POSTE_ETAT_FINALISE,)
79 if len(dae_importees) > 0:
80 qs = qs.extra(where=['id NOT IN (%s)' % ", ".join(dae_importees)])
47d7067b
OL
81 return qs
82
83