from django.db import models
from django.db.models import Q
from utils import get_employe_from_user
-from workflow import POSTE_ETAT_HAUTE_DIRECTION, \
- POSTE_ETAT_ACCIOR, \
- POSTE_ETAT_ABF, \
- DOSSIER_ETAT_ACCIOR, \
- DOSSIER_ETAT_ABF, \
- MAP_GROUPE_ETATS_A_FAIRE
+from workflow import MAP_GROUPE_ETATS_A_FAIRE
from workflow import dae_groupes, \
grp_administrateurs, \
grp_directeurs_bureau, \
grp_service_utilisateurs, \
grp_correspondants_rh
+from rh.managers import DossierManager as RHDossierManager
+from rh.managers import PosteManager as RHPosteManager
+from rh.managers import PosteComparaisonManager as RHPosteComparaisonManager
+from rh.managers import DossierComparaisonManager as RHDossierComparaisonManager
-class SecurityManager(models.Manager):
- prefixe_service = None
- prefixe_implantation = None
+class TodoManagerMixin(object):
def mes_choses_a_faire(self, user):
q = Q()
return qs
- def ma_region_ou_service(self, user):
- """
- Filtrage des postes en fonction du user connecté (region / service)
- On s'intéresse aussi au groupe auquel appartient le user car certains groupes
- peuvent tout voir.
- """
- employe = get_employe_from_user(user)
-
- ############################################
- # TRAITEMENT NORMAL
- ############################################
- # REGION
- q = Q(**{ self.prefixe_implantation : employe.implantation.region })
-
- # SERVICE
- if self.prefixe_service and grp_service_utilisateurs in user.groups.all():
- q = q | Q(**{ self.prefixe_service : employe.service})
-
- liste = self.get_query_set().filter(q)
-
- ############################################
- # TRAITEMENT ACCIOR
- ############################################
- if grp_accior in user.groups.all():
- liste = self.get_query_set().all()
-
- ############################################
- # TRAITEMENT ABF
- ############################################
- if grp_abf in user.groups.all():
- liste = self.get_query_set().all()
-
- ############################################
- # TRAITEMENT HAUTE DIRECTION
- ############################################
- if grp_haute_direction in user.groups.all():
- liste = self.get_query_set().all()
-
- ############################################
- # TRAITEMENT DRH
- ############################################
- if grp_drh in user.groups.all() or grp_drh2 in user.groups.all():
- liste = self.get_query_set().all()
-
- return liste
-
-
-class PosteManager(SecurityManager):
- """
- Chargement de tous les objets FK existants sur chaque QuerySet.
- """
- prefixe_service = "service"
- prefixe_implantation = "implantation__region"
-
- def ma_region_ou_service(self, user):
- return super(PosteManager, self).ma_region_ou_service(user).filter(actif=True)
-
- def get_query_set(self):
- fkeys = (
- 'id_rh',
- 'responsable',
- 'implantation',
- 'implantation.bureau_rattachement',
- 'type_poste',
- 'service',
- 'classement_min',
- 'classement_max',
- 'valeur_point_min',
- 'valeur_point_max',
- )
- return super(PosteManager, self).get_query_set() \
- .select_related(*fkeys).all()
-
-
-class DossierManager(SecurityManager):
- prefixe_service = "poste__service"
- prefixe_implantation = "poste__implantation__region"
-
- def get_query_set(self):
- fkeys = (
- 'poste',
- )
- return super(DossierManager, self).get_query_set() \
- .select_related(*fkeys).all()
+class DossierManager(RHDossierManager, TodoManagerMixin):
+ pass
- def ma_region_ou_service(self, user):
- return super(DossierManager, self).ma_region_ou_service(user).filter(poste__actif=True)
+class PosteManager(RHPosteManager, TodoManagerMixin):
+ pass
+class PosteComparaisonManager(RHPosteComparaisonManager, TodoManagerMixin):
+ pass
-class PosteComparaisonManager(SecurityManager):
- use_for_related_fields = True
- prefixe_implantation = "implantation__region"
+class DossierComparaisonManager(RHDossierComparaisonManager, TodoManagerMixin):
+ pass
-class DossierComparaisonManager(SecurityManager):
- use_for_related_fields = True
- prefixe_implantation = "implantation__region"