Browse Source

Localiza url do subnav.yaml nas variações do crud

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.
pull/507/head
LeandroRoberto 9 years ago
parent
commit
66ecc07319
  1. 25
      sapl/base/templatetags/menus.py

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

Loading…
Cancel
Save