Skip to content

Commit

Permalink
[#471] Fix up nav_named_link() so now uses nav_link()
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Feb 26, 2013
1 parent 026e135 commit 6bf2348
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
23 changes: 16 additions & 7 deletions ckan/lib/helpers.py
Expand Up @@ -335,28 +335,37 @@ def _create_link_text(text, **kwargs):
)


def nav_link(text, controller, **kwargs):
def nav_link(text, *args, **kwargs):
'''
params
class_: pass extra class(s) to add to the <a> tag
icon: name of ckan icon to use within the link
condition: if False then no link is returned
'''
if kwargs.pop('condition', True):
if len(args) > 1:
raise Exception('Too many unnamed parameters supplied')
if len == 1:
kwargs['controller'] = controller
link = _link_to(text, **kwargs)
log.warning('h.nav_link() please supply controller as a named '
'parameter not a positional one')
named_route = kwargs.pop('named_route', '')
if kwargs.pop('condition', True):
if named_route:
link = _link_to(text, named_route, **kwargs)
else:
link = _link_to(text, **kwargs)
else:
link = ''
return link


@maintain.deprecated('h.nav_named_link is deprecated please '
'use h.build_nav\nNOTE: the order of the first two '
'parameters is reversed in the new function')
def nav_named_link(text, name, **kwargs):
'use h.nav_link\nNOTE: you will need to pass the '
'route_name as a named parameter')
def nav_named_link(text, named_route, **kwargs):
'''Create a link for a named route.
Deprecated in ckan 2.0 '''
return build_nav(name, text, **kwargs)
return nav_link(text, named_route=named_route, **kwargs)


@maintain.deprecated('h.subnav_link is deprecated please '
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates_legacy/layout_base.html
Expand Up @@ -75,7 +75,7 @@
<div id="mainmenu">
<span py:if="h.check_access('package_create')">${h.nav_link(_('Add a dataset'), controller='package', action='new')}</span>
${h.nav_link(_('Search'), controller='package', action='search', highlight_actions = 'new index')}
${h.build_nav('%s_index' % h.default_group_type(), _('Groups'))}
${h.nav_link(_('Groups'), named_route='%s_index' % h.default_group_type())}
${h.nav_link(_('About'), controller='home', action='about')}
</div>
</div>
Expand Down

0 comments on commit 6bf2348

Please sign in to comment.