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']