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
@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 {
@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']
)
}
@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)
@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']
)
}