Skip to content

Commit

Permalink
Add action to get number of datasets in a showcase
Browse files Browse the repository at this point in the history
Necessary because the action ckanext_showcase_package_list now returns a paginated result
  • Loading branch information
bellisk committed Aug 15, 2022
1 parent 83c7b63 commit 294e71f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions ckanext/showcase/logic/action/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def get_actions():
ckanext.showcase.logic.action.delete.showcase_package_association_delete,
'ckanext_showcase_package_list':
ckanext.showcase.logic.action.get.showcase_package_list,
'ckanext_showcase_package_list_count':
ckanext.showcase.logic.action.get.showcase_package_list_count,
'ckanext_package_showcase_list':
ckanext.showcase.logic.action.get.package_showcase_list,
'ckanext_showcase_admin_add':
Expand Down
27 changes: 27 additions & 0 deletions ckanext/showcase/logic/action/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,33 @@ def showcase_list(context, data_dict):
return showcase_list


@toolkit.side_effect_free
def showcase_package_list_count(context, data_dict):
'''Get number of packages associated with a showcase.
:param showcase_id: id or name of the showcase
:type showcase_id: string
:rtype: int
'''

toolkit.check_access('ckanext_showcase_package_list', context, data_dict)

# validate the incoming data_dict
validated_data_dict, errors = validate(data_dict,
showcase_package_list_schema(),
context)

if errors:
raise toolkit.ValidationError(errors)

# get a list of package ids associated with showcase id
pkg_id_list = ShowcasePackageAssociation.get_package_ids_for_showcase(
validated_data_dict['showcase_id'])

return len(pkg_id_list)


@toolkit.side_effect_free
def showcase_package_list(context, data_dict):
'''Get paginated list of packages associated with a showcase.
Expand Down
5 changes: 2 additions & 3 deletions ckanext/showcase/plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,8 @@ def _add_to_pkg_dict(self, context, pkg_dict):
qualified=True)

# Add dataset count
pkg_dict[u'num_datasets'] = len(
tk.get_action('ckanext_showcase_package_list')(
context, {'showcase_id': pkg_dict['id']}))
pkg_dict[u'num_datasets'] = tk.get_action('ckanext_showcase_package_list_count')(
context, {'showcase_id': pkg_dict['id']})

# Rendered notes
if showcase_helpers.get_wysiwyg_editor() == 'ckeditor':
Expand Down

0 comments on commit 294e71f

Please sign in to comment.