Skip to content

Commit

Permalink
[#890] New get_action helper and remove package_show extra work
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Jun 25, 2013
1 parent 25cdea3 commit 1354683
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 8 additions & 0 deletions ckan/lib/helpers.py
Expand Up @@ -611,6 +611,13 @@ def check_access(action, data_dict=None):
return authorized


def get_action(action_name, data_dict=None):
'''Calls an action function from a template.'''
if data_dict is None:
data_dict = {}
return logic.get_action(action_name)({}, data_dict)


def linked_user(user, maxlength=0, avatar=20):
if user in [model.PSEUDO_USER__LOGGED_IN, model.PSEUDO_USER__VISITOR]:
return user
Expand Down Expand Up @@ -1582,6 +1589,7 @@ def SI_number_span(number):
'subnav_named_route',
'default_group_type',
'check_access',
'get_action',
'linked_user',
'group_name_to_title',
'markdown_extract',
Expand Down
5 changes: 1 addition & 4 deletions ckan/logic/action/get.py
Expand Up @@ -754,12 +754,9 @@ def package_show(context, data_dict):
for item in plugins.PluginImplementations(plugins.IPackageController):
item.after_show(context, package_dict)

package_dict['num_followers'] = logic.get_action('dataset_follower_count')(
{'model': model, 'session': model.Session},
{'id': package_dict['id']})

return package_dict


def resource_show(context, data_dict):
'''Return the metadata of a resource.
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/package/read_base.html
Expand Up @@ -56,7 +56,7 @@ <h1 class="heading">{{ pkg.title or pkg.name }}</h1>
<div class="nums">
<dl>
<dt>{{ _('Followers') }}</dt>
<dd>{{ h.SI_number_span(pkg.num_followers) }}</dd>
<dd>{{ h.SI_number_span(h.get_action('dataset_follower_count', {'id': pkg.id})) }}</dd>
</dl>
</div>
<div class="follow_button">
Expand Down

0 comments on commit 1354683

Please sign in to comment.