From edeed5e72a9bec1b2d1111110db86941d77b40d5 Mon Sep 17 00:00:00 2001 From: Rae Knowler Date: Mon, 15 Aug 2022 11:56:48 +0200 Subject: [PATCH] WIP: display showcase datasets paginated on manage-datasets page --- .../i18n/de/LC_MESSAGES/ckanext-showcase.mo | Bin 9304 -> 9304 bytes .../i18n/fr/LC_MESSAGES/ckanext-showcase.mo | Bin 9034 -> 9551 bytes .../LC_MESSAGES/ckanext-showcase.mo | Bin 8355 -> 8355 bytes .../templates/showcase/manage_datasets.html | 11 ++++- ckanext/showcase/utils.py | 43 +++++++++++++----- 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/ckanext/showcase/i18n/de/LC_MESSAGES/ckanext-showcase.mo b/ckanext/showcase/i18n/de/LC_MESSAGES/ckanext-showcase.mo index c77f1d2ee73e3269a46ee5a7f9f289f0469b4e81..9b695ee07f944ec3552ef459b432238f9b7096f1 100644 GIT binary patch delta 16 XcmccNal>Q7BN1j}J(JB(MT+?WKyL=E delta 16 XcmccNal>Q7BN1jxJ;TjUMT+?WK#c~l diff --git a/ckanext/showcase/i18n/fr/LC_MESSAGES/ckanext-showcase.mo b/ckanext/showcase/i18n/fr/LC_MESSAGES/ckanext-showcase.mo index 2d57081380d93ea85da4339cea45ad574d0374e7..4f6291750a4da2321d268a7eaecf1d446c13ed97 100644 GIT binary patch delta 2232 zcmZA1eQ4EH9LMo<_ndR?(YfdS?%bSfkEN@0wxTV~nfpf&tq`x?J9q8w{%rSmS4_4m zR7g_JxJ@vlf5u!ciR?l|8dO43BpKNQC?Od5$1FxANi*vG*?!X8Z;UatqQ*i{daTFKhIA-7nSb%5T=NDbC zVjJz#*n|yq-e643JUv%1V_3(7DNMtq_ZYJT%UtVG0oP(Kb|G__XWY6U8EOXbUW{Ru z$Cyb}LLZTRFa{xhtZ2K zqgFnF`FIwU$VDu{s~A(@848+U2~mo$2utxktisJm7qicG2sP0m+=*|Zc5Vi@qn7D| zr*H+HMGLRFrZBjcdQCR_uMV4OXh8>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-y(!J(j?Uq}_4=%! zcO&k__wgpq!RbV)aT`!~-s<@|>TUSW^Bk)GulNT(M+M^iM%Z&HJVZrW!Yt&IRiNrs zs3V<^8qk0`p%&D_A9=Q;#wC%tZ69jKCs5i8p)3kkhwL?89!aeLfl6N&Q_+Vm~gzS~7SccHm-kQS&~*2G+L#VX9** z&cjovB)f-tZH90)K1RJZ?~pL+w-oCzh1&6Dul^6dO?_4{^ABk&>ZCex7Jh;1e;%C$ z6dqD2!eDvk?rKmwY(mzwR^(8u3v00#tME4Ju19dbyy8}hs#l^;v>r8X4QiekF2MsB z#v4;fA+E`)E7EznN%x!FJ3e>c=uflKGyE;?L4RPR+h4HGm!4g?p>Ws7k)0og6XE)J zv@H=0?+9&aPaiGpC<^Urk8bOTY=8ZMTVAxy=N>O^$#QEZ{hXDaR~B>o%DQvi=86lx cl6W)``5+NZY>%XZ@kBTgjVGd?bVTCz5+zQ@fB*mh 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 2465e7d6a9423e06fdd99e4a4f633dd3bd0ab71a..3e5044a2952b3ec4c42ce97d819ef6725b115ed8 100644 GIT binary patch delta 16 YcmZ4NxY%*SPZ4HgJ(JCUM3!>{06Q`UlK=n! delta 16 YcmZ4NxY%*SPZ4HwJ%i1EM3!>{06RJclK=n! 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 @@

{{ _('Datasets in this showcase') }}

- {% if c.showcase_pkgs %} + {% if pkg_page %}
@@ -113,7 +113,7 @@

{{ _('Datasets in this showcase') }}

- {% for package in c.showcase_pkgs %} + {% for package in pkg_page.items %} {% set truncate = truncate or 180 %} {% set truncate_title = truncate_title or 80 %} {% set title = package.title or package.name %} @@ -133,6 +133,13 @@

{% endfor %}

+ {% if pkg_page.pager() %} + + + + + + {% endif %}
{% else %} diff --git a/ckanext/showcase/utils.py b/ckanext/showcase/utils.py index 38e1fc16..6addbdd5 100644 --- a/ckanext/showcase/utils.py +++ b/ckanext/showcase/utils.py @@ -5,9 +5,11 @@ import logging from collections import OrderedDict +from pylons import url as _pylons_default_url import six from six.moves.urllib.parse import urlencode +from ckan.common import is_flask_request import ckan.model as model import ckan.plugins as p import ckan.logic as logic @@ -83,32 +85,49 @@ def read_view(id): return tk.abort(401, _('Unauthorized to read showcase')) # get showcase packages + page = _get_showcase_packages_page(context, page_number) + + package_type = DATASET_TYPE_NAME + return tk.render('showcase/read.html', + extra_vars={'dataset_type': package_type, 'page': page}) + + +def _get_showcase_packages_page(context, page_number): num_datasets = tk.get_action('ckanext_showcase_package_list_count')( context, { 'showcase_id': tk.g.pkg_dict['id'] }) limit = int(tk.config.get(u'ckan.datasets_per_page', 20)) offset = (page_number - 1) * limit - showcase_pkgs = tk.get_action('ckanext_showcase_package_list')( context, { 'showcase_id': tk.g.pkg_dict['id'], 'limit': limit, 'offset': offset }) - page = h.Page( collection=showcase_pkgs, page=page_number, - url=h.pager_url, + url=_pager_url, item_count=num_datasets, items_per_page=limit, presliced_list=True ) + return page - package_type = DATASET_TYPE_NAME - return tk.render('showcase/read.html', - extra_vars={'dataset_type': package_type, 'page': page}) + +def _pager_url(page, **kwargs): + pargs = [] + if is_flask_request(): + pargs.append(tk.request.endpoint) + else: + routes_dict = _pylons_default_url.environ['pylons.routes_dict'] + kwargs['controller'] = routes_dict['controller'] + kwargs['action'] = routes_dict['action'] + if routes_dict.get('id'): + kwargs['id'] = routes_dict['id'] + kwargs['page'] = page + return tk.url_for(*pargs, **kwargs) def manage_datasets_view(id): @@ -202,13 +221,13 @@ def manage_datasets_view(id): _add_dataset_search(tk.g.pkg_dict['id'], tk.g.pkg_dict['name']) - # get showcase packages - tk.g.showcase_pkgs = tk.get_action('ckanext_showcase_package_list')( - context, { - 'showcase_id': tk.g.pkg_dict['id'] - }) + # get showcase packages page + pkg_page_number = h.get_page_number(tk.request.params, key='pkg_page') + log.warn(pkg_page_number) + pkg_page = _get_showcase_packages_page(context, pkg_page_number) + log.warn(pkg_page) - return tk.render('showcase/manage_datasets.html') + return tk.render('showcase/manage_datasets.html', extra_vars={'pkg_page': pkg_page}) def _add_dataset_search(showcase_id, showcase_name): '''