From 66ecc0731988581edb998ca32be12b09a82fcde7 Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Wed, 22 Jun 2016 00:10:19 -0300 Subject: [PATCH] =?UTF-8?q?Localiza=20url=20do=20subnav.yaml=20nas=20varia?= =?UTF-8?q?=C3=A7=C3=B5es=20do=20crud?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Localiza url do subnav.yaml nas variações do crud da view do request caso o acesso seja por uma de suas variações com o intuito de manter a classe "active" no subnav correto ao serem ativadas funcionalidades de adição, edição e exclusão. --- sapl/base/templatetags/menus.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/sapl/base/templatetags/menus.py b/sapl/base/templatetags/menus.py index a3c104103..ce67143ea 100644 --- a/sapl/base/templatetags/menus.py +++ b/sapl/base/templatetags/menus.py @@ -44,18 +44,18 @@ def subnav(context, path=None): """ yaml_template = template.loader.get_template(yaml_path) menu = yaml.load(open(yaml_template.origin.name, 'r')) - resolve_urls_inplace(menu, root_pk, app, request.path) + resolve_urls_inplace(menu, root_pk, app, context) except: pass return {'menu': menu} -def resolve_urls_inplace(menu, pk, app, request_path): +def resolve_urls_inplace(menu, pk, app, context): if isinstance(menu, list): list_active = '' for item in menu: - menuactive = resolve_urls_inplace(item, pk, app, request_path) + menuactive = resolve_urls_inplace(item, pk, app, context) list_active = menuactive if menuactive else list_active if not isinstance(item, list): item['active'] = menuactive @@ -63,10 +63,25 @@ def resolve_urls_inplace(menu, pk, app, request_path): return list_active else: if 'url' in menu: + url_name = menu['url'] menu['url'] = reverse('%s:%s' % (app, menu['url']), kwargs={'pk': pk}) - menu['active'] = 'active' if request_path == menu['url'] else '' + menu['active'] = 'active'\ + if context['request'].path == menu['url'] else '' + + if not menu['active']: + # se não encontrada, procura a url acionada dentro do crud, caso + # seja um. + view = context['view'] + if hasattr(view, '__class__') and\ + hasattr(view.__class__, 'crud'): + urls = view.__class__.crud.get_urls() + for u in urls: + if u.name == url_name: + menu['active'] = 'active' + break + if 'children' in menu: menu['active'] = resolve_urls_inplace( - menu['children'], pk, app, request_path) + menu['children'], pk, app, context) return menu['active']