PEP8
[auf_rh_dae.git] / project / rh / templatetags / rapports.py
index 23cb2f2..08045fa 100644 (file)
@@ -6,10 +6,10 @@ from django.utils.encoding import smart_unicode
 from django.template import Library
 from django.utils.http import urlencode
 
-from auf.django.references.models import Implantation, Region
+from auf.django.references.models import \
+        Implantation, Region, ZoneAdministrative
 
 from project import groups
-from project.groups import get_employe_from_user
 
 from project.rh.models import TypeContrat
 
@@ -40,6 +40,18 @@ def filter_region(context, prefix=None):
 
 
 @register.inclusion_tag('admin/filter.html', takes_context=True)
+def filter_zone_administrative(context, prefix=None):
+    label = "".join([prefix or "", "implantation__zone_administrative"])
+    return {
+        'title': u"zone administrative",
+        'choices': prepare_choices(
+            ZoneAdministrative.objects.values_list('code', 'nom'), label,
+            context, remove=['pays', 'nord_sud']
+        )
+    }
+
+
+@register.inclusion_tag('admin/filter.html', takes_context=True)
 def filter_implantation(context, prefix=None):
     label = "".join([prefix or "", "implantation"])
     return {
@@ -51,27 +63,35 @@ def filter_implantation(context, prefix=None):
 
 
 @register.inclusion_tag('admin/filter.html', takes_context=True)
-def filter_region_contrat(context):
+def filter_zone_administrative_contrat(context):
     request = context['request']
-    user_groups = request.user.groups.all()
-    if groups.grp_correspondants_rh in user_groups or\
-         groups.grp_administrateurs in user_groups or\
-         groups.grp_directeurs_bureau in user_groups:
-        employe = get_employe_from_user(request.user)
-        regions = Region.objects.filter(id=employe.implantation.region.id)
+    user_groups = [g.name for g in request.user.groups.all()]
+    if groups.CORRESPONDANT_RH in user_groups or\
+         groups.ADMINISTRATEURS in user_groups or\
+         groups.DIRECTEUR_DE_BUREAU in user_groups:
+        employe = groups.get_employe_from_user(request.user)
+        zones = ZoneAdministrative.objects.filter(
+            code=employe.implantation.zone_administrative.code
+        )
     else:
-       regions = Region.objects.all()
-    return {'title': u"région",
-            'choices': prepare_choices(regions.values_list('id', 'nom'), 'dossier__poste__implantation__region', context, remove=['pays', 'nord_sud'])}
+        zones = ZoneAdministrative.objects.all()
+    return {
+        'title': u"région",
+        'choices': prepare_choices(
+            zones.values_list('code', 'nom'),
+            'dossier__poste__implantation__zone_administrative',
+            context, remove=['pays', 'nord_sud']
+        )
+    }
 
 
 @register.inclusion_tag('admin/filter.html', takes_context=True)
-def filter_region_dossier(context):
+def filter_zone_administrative_dossier(context):
     return {
         'title': u"région",
         'choices': prepare_choices(
-            Region.objects.values_list('id', 'nom'),
-            'poste__implantation__region', context,
+            ZoneAdministrative.objects.values_list('code', 'nom'),
+            'poste__implantation__zone_administrative', context,
             remove=['pays', 'nord_sud']
         )
     }
@@ -91,16 +111,23 @@ def filter_implantation_dossier(context):
 @register.inclusion_tag('admin/filter.html', takes_context=True)
 def filter_implantation_contrat(context):
     request = context['request']
-    user_groups = request.user.groups.all()
-    if groups.grp_correspondants_rh in user_groups or\
-         groups.grp_administrateurs in user_groups or\
-         groups.grp_directeurs_bureau in user_groups:
-        employe = get_employe_from_user(request.user)
-        implantations = Implantation.objects.filter(region=employe.implantation.region)
+    user_groups = [g.name for g in request.user.groups.all()]
+    if groups.CORRESPONDANT_RH in user_groups or\
+         groups.ADMINISTRATEURS in user_groups or\
+         groups.DIRECTEUR_DE_BUREAU in user_groups:
+        employe = groups.get_employe_from_user(request.user)
+        implantations = Implantation.objects.filter(
+            zone_administrative=employe.implantation.zone_administrative
+        )
     else:
-       implantations = Implantation.objects.all()
-    return {'title': u"implantation",
-            'choices': prepare_choices(implantations.values_list('id', 'nom'), 'dossier__poste__implantation', context)}
+        implantations = Implantation.objects.all()
+    return {
+        'title': u"implantation",
+        'choices': prepare_choices(
+            implantations.values_list('id', 'nom'),
+            'dossier__poste__implantation', context
+        )
+    }
 
 
 @register.inclusion_tag('admin/filter.html', takes_context=True)
@@ -194,12 +221,12 @@ def filter_a_venir(context):
 
 
 @register.inclusion_tag('admin/filter_select.html', takes_context=True)
-def filter_region_remun(context):
+def filter_zone_administrative_remun(context):
     return {
         'title': u"région",
         'choices': prepare_choices(
-            Region.objects.values_list('id', 'nom'),
-            'dossiers__poste__implantation__region', context,
+            ZoneAdministrative.objects.values_list('code', 'nom'),
+            'dossiers__poste__implantation__zone_administrative', context,
             remove=['pays', 'nord_sud']
         )
     }