diff --git a/ckanext/showcase/i18n/de/LC_MESSAGES/ckanext-showcase.mo b/ckanext/showcase/i18n/de/LC_MESSAGES/ckanext-showcase.mo index c77f1d2e..9b695ee0 100644 Binary files a/ckanext/showcase/i18n/de/LC_MESSAGES/ckanext-showcase.mo and b/ckanext/showcase/i18n/de/LC_MESSAGES/ckanext-showcase.mo differ diff --git a/ckanext/showcase/i18n/fr/LC_MESSAGES/ckanext-showcase.mo b/ckanext/showcase/i18n/fr/LC_MESSAGES/ckanext-showcase.mo index 2d570813..4f629175 100644 Binary files a/ckanext/showcase/i18n/fr/LC_MESSAGES/ckanext-showcase.mo and b/ckanext/showcase/i18n/fr/LC_MESSAGES/ckanext-showcase.mo differ diff --git a/ckanext/showcase/i18n/zh_Hant_TW/LC_MESSAGES/ckanext-showcase.mo b/ckanext/showcase/i18n/zh_Hant_TW/LC_MESSAGES/ckanext-showcase.mo index 2465e7d6..3e5044a2 100644 Binary files a/ckanext/showcase/i18n/zh_Hant_TW/LC_MESSAGES/ckanext-showcase.mo and b/ckanext/showcase/i18n/zh_Hant_TW/LC_MESSAGES/ckanext-showcase.mo differ diff --git a/ckanext/showcase/logic/action/__init__.py b/ckanext/showcase/logic/action/__init__.py index 43ab2d14..72a5e083 100644 --- a/ckanext/showcase/logic/action/__init__.py +++ b/ckanext/showcase/logic/action/__init__.py @@ -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': diff --git a/ckanext/showcase/logic/action/get.py b/ckanext/showcase/logic/action/get.py index aa6b7de0..39ac1cd5 100644 --- a/ckanext/showcase/logic/action/get.py +++ b/ckanext/showcase/logic/action/get.py @@ -44,12 +44,46 @@ 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): - '''List packages associated with a showcase. + '''Get paginated list of packages associated with a showcase. :param showcase_id: id or name of the showcase :type showcase_id: string + :param limit: the list of datasets will be broken into pages of at most + ``limit`` datasets per page and only one page will be returned at a + time (optional, default: ckan.datasets_per_page or 20) + :type limit: int + :param offset: when ``limit`` is given, the offset to start + returning packages from + :type offset: int :rtype: list of dictionaries ''' @@ -64,21 +98,26 @@ def showcase_package_list(context, data_dict): if errors: raise toolkit.ValidationError(errors) + # Todo: Add separate config option for this instead of reusing this one. + limit = data_dict.get( + 'limit', int(toolkit.config.get('ckan.datasets_per_page', 20))) + offset = data_dict.get('offset', 0) + # get a list of package ids associated with showcase id pkg_id_list = ShowcasePackageAssociation.get_package_ids_for_showcase( validated_data_dict['showcase_id']) pkg_list = [] if pkg_id_list: - # for each package id, get the package dict and append to list if - # active + # for each package id in the range given by limit and offset, + # get the package dict and append to list if active id_list = [] - for pkg_id in pkg_id_list: + for pkg_id in pkg_id_list[offset:offset + limit]: id_list.append(pkg_id[0]) - q = 'id:(' + ' OR '.join(['{0}'.format(x) for x in id_list]) + ')' + fq = 'id:(' + ' OR '.join(['{0}'.format(x) for x in id_list]) + ')' _pkg_list = toolkit.get_action('package_search')( context, - {'q': q, 'rows': 100}) + {'fq': fq, 'rows': 100}) pkg_list = _pkg_list['results'] return pkg_list diff --git a/ckanext/showcase/plugin/__init__.py b/ckanext/showcase/plugin/__init__.py index ff36a0da..14708d9e 100644 --- a/ckanext/showcase/plugin/__init__.py +++ b/ckanext/showcase/plugin/__init__.py @@ -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': diff --git a/ckanext/showcase/templates/showcase/manage_datasets.html b/ckanext/showcase/templates/showcase/manage_datasets.html index b1da5c6e..cd87026e 100644 --- a/ckanext/showcase/templates/showcase/manage_datasets.html +++ b/ckanext/showcase/templates/showcase/manage_datasets.html @@ -94,7 +94,7 @@