Merge branch 'master' into dae_refactoring_process
[auf_rh_dae.git] / project / dae / forms.py
index e2ac873..929b73c 100644 (file)
@@ -87,16 +87,12 @@ class BaseInlineFormSetWithInitial(BaseInlineFormSet):
 def _implantation_choices(obj, request):
     # TRAITEMENT NORMAL
     employe = groups.get_employe_from_user(request.user)
-    # SERVICE
-    if groups.is_user_dans_services_centraux(request.user):
-        q = Q(**{'id': employe.implantation_id})
-    # REGION
-    else:
-        q = Q(**{'region': employe.implantation.region})
+    q = Q(**{'zone_administrative': employe.implantation.zone_administrative})
 
     # TRAITEMENT DRH
     user_groupes = [g.name for g in request.user.groups.all()]
-    if groups.DRH_NIVEAU_1 in user_groupes:
+    if groups.DRH_NIVEAU_1 in user_groupes or \
+       groups.DRH_NIVEAU_2 in user_groupes:
         q = Q()
     return [('', '----------')] + \
             [(i.id, unicode(i), )for i in ref.Implantation.objects.filter(q)]
@@ -105,21 +101,20 @@ def _implantation_choices(obj, request):
 def _employe_choices(obj, request):
     # TRAITEMENT NORMAL
     employe = groups.get_employe_from_user(request.user)
-    # SERVICE
-    if groups.is_user_dans_services_centraux(request.user):
-        q_dae_region_service = Q(poste__implantation=employe.implantation)
-        q_rh_region_service = Q(poste__implantation=employe.implantation)
-    # REGION
-    else:
-        q_dae_region_service = Q(
-            poste__implantation__region=employe.implantation.region
+    q_dae_region_service = Q(
+        poste__implantation__zone_administrative=(
+            employe.implantation.zone_administrative
         )
-        q_rh_region_service = Q(
-            poste__implantation__region=employe.implantation.region
+    )
+    q_rh_region_service = Q(
+        poste__implantation__zone_administrative=(
+            employe.implantation.zone_administrative
         )
+    )
     # TRAITEMENT DRH
     user_groupes = [g.name for g in request.user.groups.all()]
-    if groups.DRH_NIVEAU_1 in user_groupes:
+    if groups.DRH_NIVEAU_1 in user_groupes or \
+       groups.DRH_NIVEAU_2 in user_groupes:
         q_dae_region_service = Q()
         q_rh_region_service = Q()
 
@@ -161,16 +156,16 @@ def _employe_choices(obj, request):
     employes_avec_dae = [d.employe_id for d in dae.Dossier.objects.all()]
     employes_orphelins = dae.Employe.objects.exclude(id__in=employes_avec_dae)
 
-    def option_label(employe):
-        return "%s %s" % (employe.nom.upper(), employe.prenom.title())
+    def option_label(employe, extra=""):
+        if extra:
+            extra = " [%s]" % extra
+        return "%s %s %s" % (employe.nom.upper(), employe.prenom.title(), extra)
 
-    return [('', 'Nouvel employé')] + \
-           sorted(
-               [('dae-%s' % p.id, option_label(p))
-                for p in dae_ | copies | employes_orphelins] +
-               [('rh-%s' % p.id, option_label(p)) for p in rhv1],
-               key=lambda t: t[1]
-           )
+    lbl_rh = sorted([('rh-%s' % p.id, option_label(p, "existant dans rh")) for p in rhv1],
+            key=lambda t: t[1])
+    lbl_dae = sorted([('dae-%s' % p.id, option_label(p)) for p in dae_ | copies | employes_orphelins],
+            key=lambda t: t[1])
+    return [('', 'Nouvel employé')] + lbl_rh + lbl_dae
 
 
 def label_poste_display(poste):