@ -44,18 +44,18 @@ def subnav(context, path=None):
"""
"""
yaml_template = template . loader . get_template ( yaml_path )
yaml_template = template . loader . get_template ( yaml_path )
menu = yaml . load ( open ( yaml_template . origin . name , ' r ' ) )
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 :
except :
pass
pass
return { ' menu ' : menu }
return { ' menu ' : menu }
def resolve_urls_inplace ( menu , pk , app , request_path ) :
def resolve_urls_inplace ( menu , pk , app , context ) :
if isinstance ( menu , list ) :
if isinstance ( menu , list ) :
list_active = ' '
list_active = ' '
for item in menu :
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
list_active = menuactive if menuactive else list_active
if not isinstance ( item , list ) :
if not isinstance ( item , list ) :
item [ ' active ' ] = menuactive
item [ ' active ' ] = menuactive
@ -63,10 +63,25 @@ def resolve_urls_inplace(menu, pk, app, request_path):
return list_active
return list_active
else :
else :
if ' url ' in menu :
if ' url ' in menu :
url_name = menu [ ' url ' ]
menu [ ' url ' ] = reverse ( ' %s : %s ' % ( app , menu [ ' url ' ] ) ,
menu [ ' url ' ] = reverse ( ' %s : %s ' % ( app , menu [ ' url ' ] ) ,
kwargs = { ' pk ' : pk } )
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 :
if ' children ' in menu :
menu [ ' active ' ] = resolve_urls_inplace (
menu [ ' active ' ] = resolve_urls_inplace (
menu [ ' children ' ] , pk , app , request_path )
menu [ ' children ' ] , pk , app , context )
return menu [ ' active ' ]
return menu [ ' active ' ]