Skip to content

Commit

Permalink
Merge branch '471-helper-clean-link-functions'
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Mar 21, 2013
2 parents 5a75b3c + c1b806d commit a423c2d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 25 deletions.
43 changes: 31 additions & 12 deletions ckan/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,38 +323,57 @@ 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 args:
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


def nav_named_link(text, name, **kwargs):
'''Create a link for a named route.'''
return _link_to(text, name, **kwargs)
@maintain.deprecated('h.nav_named_link is deprecated please '
'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 nav_link(text, named_route=named_route, **kwargs)


@maintain.deprecated('h.subnav_link is deprecated please '
'use h.nav_link\nNOTE: if action is passed as the second '
'parameter make sure it is passed as a named parameter '
'eg. `action=\'my_action\'')
def subnav_link(text, action, **kwargs):
'''Create a link for a named route.'''
'''Create a link for a named route.
Deprecated in ckan 2.0 '''
kwargs['action'] = action
return _link_to(text, **kwargs)
return nav_link(text, **kwargs)


@maintain.deprecated('h.subnav_named_route is deprecated please '
'use h.nav_named_link')
def subnav_named_route(text, routename, **kwargs):
'use h.nav_link\nNOTE: you will need to pass the '
'route_name as a named parameter')
def subnav_named_route(text, named_route, **kwargs):
'''Generate a subnav element based on a named route
Deprecated in ckan 2.0 '''
return nav_named_link(text, routename, **kwargs)
return nav_link(text, named_route=named_route, **kwargs)


def build_nav_main(*args):
Expand Down Expand Up @@ -433,7 +452,7 @@ def _make_menu_item(menu_item, title, **kw):
if need not in kw:
raise Exception('menu item `%s` need parameter `%s`'
% (menu_item, need))
link = nav_named_link(title, menu_item, suppress_active_class=True, **item)
link = _link_to(title, menu_item, suppress_active_class=True, **item)
if active:
return literal('<li class="active">') + link + literal('</li>')
return literal('<li>') + link + literal('</li>')
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates_legacy/group/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
${ h.subnav_named_route(h.icon('group_add') + _('Add a Group'), "%s_new" % h.default_group_type(), action='new')}
</li>
<li class="ckan-logged-out ${'active' if c.action=='new' else ''}">
${h.subnav_link(h.icon('group_add') + _('Login to Add a Group'), controller='group', action='new')}
${h.nav_link(h.icon('group_add') + _('Login to Add a Group'), controller='group', action='new')}
</li>
</py:otherwise>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates_legacy/layout_base.html
Original file line number Diff line number Diff line change
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.nav_named_link(_('Groups'), name='%s_index' % h.default_group_type() )}
${h.nav_link(_('Groups'), named_route='%s_index' % h.default_group_type())}
${h.nav_link(_('About'), controller='home', action='about')}
</div>
</div>
Expand Down
10 changes: 5 additions & 5 deletions ckan/templates_legacy/package/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<py:match path="minornavigation" py:if="c.pkg">
<ul class="nav nav-pills">
<li class="${'active' if c.action=='read' else ''}">${h.subnav_link(h.icon('package') + _('View'), controller='package', action='read', id=c.pkg.name)}</li>
<li class="${'active' if c.action=='read' else ''}">${h.nav_link(h.icon('package') + _('View'), controller='package', action='read', id=c.pkg.name)}</li>
<py:choose test="len(c.pkg_dict.get('resources', []))==0 and not h.check_access('package_update',{'id':c.pkg.id})">
<py:when test="True">
<li class="disabled">
Expand All @@ -34,10 +34,10 @@
</li>
</py:otherwise>
</py:choose>
<li py:if="h.asbool(config.get('ckan.dataset.show_apps_ideas', 'true'))" class="${'active' if c.action=='related' else ''}">${h.subnav_link(h.icon('package') + _('Apps, Ideas etc') + ' (%s)' % c.related_count, controller='related', action='list', id=c.pkg.name)}</li>
<li class="${'active' if c.action=='history' else ''}">${h.subnav_link(h.icon('page_stack') + _('History'), controller='package', action='history', id=c.pkg.name)}</li>
<li py:if="h.asbool(config.get('ckan.dataset.show_apps_ideas', 'true'))" class="${'active' if c.action=='related' else ''}">${h.nav_link(h.icon('package') + _('Apps, Ideas etc') + ' (%s)' % c.related_count, controller='related', action='list', id=c.pkg.name)}</li>
<li class="${'active' if c.action=='history' else ''}">${h.nav_link(h.icon('page_stack') + _('History'), controller='package', action='history', id=c.pkg.name)}</li>
<li class="${'active' if c.action=='followers' else ''}" style="float:right;">
${h.subnav_link(
${h.nav_link(
h.icon('followers') + _('Followers ({num_followers})').format(num_followers=h.follow_count('dataset', c.pkg_dict.id)),
controller='package',
action='followers',
Expand All @@ -50,7 +50,7 @@

<py:if test="h.check_access('package_update',{'id':c.pkg.id})">
<li class="${'active' if c.action=='edit' else ''}">
${h.subnav_link(h.icon('package_edit') + _('Settings'), controller='package', action='edit', id=c.pkg.name)}
${h.nav_link(h.icon('package_edit') + _('Settings'), controller='package', action='edit', id=c.pkg.name)}
</li>
</py:if>
<li py:if="c.user" style="float:right;">
Expand Down
4 changes: 2 additions & 2 deletions ckan/templates_legacy/package/read_core.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<div id="dataset-resources" class="resources subsection">
<h3>Resources
<py:if test="h.check_access('package_update',{'id':c.pkg.id})"> &nbsp;
${h.subnav_link(_('(edit)'), controller='package', action='editresources', id=c.pkg.name)}
${h.nav_link(_('(edit)'), controller='package', action='editresources', id=c.pkg.name)}
</py:if></h3>
<ul class="resource-list">
<py:for each="res in c.pkg_dict.get('resources', [])">
Expand All @@ -48,7 +48,7 @@ <h3>Resources
<!-- Dataset Information Section -->
<h3>Additional Information
<py:if test="h.check_access('package_update',{'id':c.pkg.id})"> &nbsp;
${h.subnav_link(_('(settings)'), controller='package', action='edit', id=c.pkg.name)}
${h.nav_link(_('(settings)'), controller='package', action='edit', id=c.pkg.name)}
</py:if></h3>
<div id="dataset-information">
<table class="table table-striped table-bordered table-condensed">
Expand Down
4 changes: 2 additions & 2 deletions ckan/templates_legacy/revision/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
>
<py:match path="minornavigation">
<ul class="nav nav-pills">
<li class="${'active' if c.action=='index' else ''}">${h.subnav_link(h.icon('page_white_stack') + _('List'), controller='revision', action='index')}</li>
<li class="${'active' if c.action=='index' else ''}">${h.nav_link(h.icon('page_white_stack') + _('List'), controller='revision', action='index')}</li>
<py:if test="c.action=='read'">
<li class="divider">|</li>
<li class="${'active' if c.action=='read' else ''}">${h.subnav_link(h.icon('page_white') + _('View'), controller='revision', action='read', id=c.id)}</li>
<li class="${'active' if c.action=='read' else ''}">${h.nav_link(h.icon('page_white') + _('View'), controller='revision', action='read', id=c.id)}</li>
</py:if>
</ul>
</py:match>
Expand Down
4 changes: 2 additions & 2 deletions ckan/templates_legacy/user/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<li class="${'active' if c.action=='edit' else ''}"><a href="${h.url_for(controller='user', action='edit')}">Edit Profile</a></li>
<li><a href="${h.url_for('/user/logout')}">Log out</a></li>
<li style="float:right;" class="${'active' if c.action=='followers' else ''}">
${h.subnav_link(
${h.nav_link(
h.icon('followers') + _('My Followers ({num_followers})').format(num_followers=h.follow_count('user', c.user_dict.id)),
controller='user',
action='followers',
Expand All @@ -24,7 +24,7 @@
<py:if test="c.id">
<li class="${'active' if c.action=='read' else ''}"><a href="${h.url_for(controller='user', action='read', id=c.user_dict.name)}">View Profile</a></li>
<li style="float:right;" class="${'active' if c.action=='followers' else ''}">
${h.subnav_link(
${h.nav_link(
h.icon('followers') + _('Followers ({num_followers})').format(num_followers=h.follow_count('user', c.user_dict.id)),
controller='user',
action='followers',
Expand Down

0 comments on commit a423c2d

Please sign in to comment.