Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

145 maximum dataset max limitation that a showcase can hold #147

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified ckanext/showcase/i18n/de/LC_MESSAGES/ckanext-showcase.mo
Binary file not shown.
Binary file modified ckanext/showcase/i18n/fr/LC_MESSAGES/ckanext-showcase.mo
Binary file not shown.
Binary file modified ckanext/showcase/i18n/zh_Hant_TW/LC_MESSAGES/ckanext-showcase.mo
Binary file not shown.
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
51 changes: 45 additions & 6 deletions ckanext/showcase/logic/action/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
'''
Expand All @@ -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

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
11 changes: 9 additions & 2 deletions ckanext/showcase/templates/showcase/manage_datasets.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ <h3 class="dataset-heading">
<section class="span6">
<div class="module-content">
<h3 class="page-heading">{{ _('Datasets in this showcase') }}</h3>
{% if c.showcase_pkgs %}
{% if pkg_page %}
<form method="POST" data-module="basic-form">
<table class="table table-bordered table-header table-hover table-bulk-edit table-edit-hover" data-module="table-selectable-rows">
<col width="8">
Expand All @@ -113,7 +113,7 @@ <h3 class="page-heading">{{ _('Datasets in this showcase') }}</h3>
</tr>
</thead>
<tbody>
{% 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 %}
Expand All @@ -133,6 +133,13 @@ <h3 class="dataset-heading">
</tr>
{% endfor %}
</tbody>
{% if pkg_page.pager() %}
<tfoot>
<tr>
<td colspan="2" class="ckanext_showcase_pagination_footer">{{ pkg_page.pager() }}</td>
</tr>
</tfoot>
{% endif %}
</table>
</form>
{% else %}
Expand Down
2 changes: 1 addition & 1 deletion ckanext/showcase/templates/showcase/read.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ <h1>
{% block secondary_help_content %}{% endblock %}

{% block package_info %}
{% snippet 'showcase/snippets/showcase_info.html', pkg=pkg, showcase_pkgs=c.showcase_pkgs %}
{% snippet 'showcase/snippets/showcase_info.html', pkg=pkg, showcase_pkgs=page.items %}
{% endblock %}

{% block package_social %}
Expand Down
59 changes: 49 additions & 10 deletions ckanext/showcase/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -64,6 +66,7 @@ def check_new_view_auth():


def read_view(id):
page_number = h.get_page_number(tk.request.params, key='pkg_page')
context = {
'model': model,
'session': model.Session,
Expand All @@ -82,14 +85,52 @@ def read_view(id):
return tk.abort(401, _('Unauthorized to read showcase'))

# get showcase packages
tk.g.showcase_pkgs = tk.get_action('ckanext_showcase_package_list')(
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=_pager_url,
item_count=num_datasets,
items_per_page=limit,
presliced_list=True,
page_param='pkg_page'
)
return page

package_type = DATASET_TYPE_NAME
return tk.render('showcase/read.html',
extra_vars={'dataset_type': package_type})

def _pager_url(**kwargs):
log.warn(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']
page_param = kwargs['page_param']
kwargs[page_param] = kwargs['page']
return tk.url_for(*pargs, **kwargs)


def manage_datasets_view(id):
Expand Down Expand Up @@ -183,13 +224,11 @@ 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')
pkg_page = _get_showcase_packages_page(context, pkg_page_number)

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):
'''
Expand Down
1 change: 0 additions & 1 deletion ckanext/showcase/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from flask import Blueprint


import ckan.lib.helpers as h
import ckan.plugins.toolkit as tk
import ckan.views.dataset as dataset
Expand Down