A CKAN extension that provides a user interface to download resources with ckanpackager.
This extension will not work without ckanpackager.
Ckanpackager is a stand-alone service that can be instructed to fetch data on a CKAN site using the datastore API, pack the data in a ZIP file and email the link to a given address. See the ckanpackager github page for more information.
The extension provides an HTML snippet that can be used to replace the Download button on resources. The new button will:
This extension uses a database table in the CKAN database to store stats about packaging events.
Path variables used below:
$INSTALL_FOLDER
(i.e. where CKAN is installed), e.g.
/usr/lib/ckan/default
$CONFIG_FILE
, e.g. /etc/ckan/default/development.ini
src
folder:cd $INSTALL_FOLDER/src
git clone https://github.com/NaturalHistoryMuseum/ckanext-ckanpackager.git
. $INSTALL_FOLDER/bin/activate
cd $INSTALL_FOLDER/src/ckanext-ckanpackager
pip install -r requirements.txt
cd $INSTALL_FOLDER/src/ckanext-ckanpackager
python setup.py develop
$CONFIG_FILE
:ckan.plugins = ... ckanpackager
There are two options that must be specified in your .ini config file.
Name | Description | Options |
---|---|---|
ckanpackager.url |
URL to the ckanpackager endpoint | |
ckanpackager.secret |
Shared secret with the ckanpackager instance |
ckan -c $CONFIG_FILE ckanpackager initdb
packager_stats
Provides statistical information about the download requests made to the
packager. All of the items in the data_dict
are optional.
from ckan.plugins import toolkit
data_dict = {
'resource_id': RESOURCE_ID,
'offset': 0,
'limit': 100,
'email': REQUESTER_EMAIL
}
toolkit.get_action('packager_stats')(
context,
data_dict
)
initdb
Initialises the ckanpackager database tables.
ckan -c $CONFIG_FILE ckanpackager initdb
Add the following snippet to templates where you want the button to appear:
{% snippet 'ckanpackager/snippets/package_resource.html',
res=res, pkg=pkg, bt_class="fas fa-download", bt_text=_('Download')
%}
Test coverage is currently extremely limited.
To run the tests in this extension, there is a Docker compose configuration available in this repository to make it easy.
To run the tests against ckan 2.9.x on Python3:
docker-compose build
docker-compose run ckan
The ckan image uses the Dockerfile in the docker/
folder which is
based on openknowledge/ckan-dev:2.9-py2
.