-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
640 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
name: Bug report | ||
about: Report a bug you've found in this extension | ||
title: '' | ||
labels: bug | ||
assignees: '' | ||
|
||
--- | ||
|
||
**Description** | ||
A clear and concise description of what the bug is. | ||
|
||
**Expected Behaviour** | ||
What you expected to happen instead. | ||
|
||
**To Reproduce** | ||
Steps to reproduce the bug. | ||
|
||
**Error Log** | ||
Paste any relevant error logs below: | ||
``` | ||
<error log here> | ||
``` | ||
|
||
**Screenshots** | ||
Add screenshots to illustrate the bug if you want. | ||
|
||
**Your Setup** | ||
- CKAN version: [e.g. 2.8.3] | ||
- Commit/version of this repo: | ||
- Browser (if relevant): [e.g. chrome, safari] | ||
|
||
**Anything Else?** | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
name: Feature request | ||
about: Suggest an feature or improvement for this extension | ||
title: '' | ||
labels: enhancement | ||
assignees: '' | ||
|
||
--- | ||
|
||
**Overview** | ||
Give a brief description of what the feature or improvement should do and why. | ||
|
||
**Possible Solutions** | ||
Do you have any ideas for how you'd want to implement it? | ||
|
||
**Anything Else?** | ||
Add any other information here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Support | ||
|
||
## Documentation | ||
- [Our API documentation](https://naturalhistorymuseum.github.io/dataportal-docs) | ||
- [CKAN documentation](http://docs.ckan.org/en/latest) | ||
|
||
## Contact Us | ||
- [Gitter](https://gitter.im/nhm-data-portal/lobby) | ||
- [Email _data@nhm.ac.uk_](mailto:data@nhm.ac.uk) | ||
- [Twitter](https://twitter.com/nhm_data) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,5 @@ | |
.Trashes | ||
ehthumbs.db | ||
Thumbs.db | ||
|
||
.coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
dist: trusty | ||
language: python | ||
|
||
python: | ||
- "2.7" | ||
|
||
install: | ||
- sh ckanext/gallery/tests/bin/build.sh | ||
|
||
services: | ||
- redis-server | ||
- postgresql | ||
|
||
addons: | ||
postgresql: "9.4" | ||
|
||
script: coverage run --source=ckanext.gallery setup.py nosetests --ckan --with-pylons=ckanext/gallery/tests/bin/test.ini --nologcapture --debug=ckantest,ckanext.gallery --rednose | ||
|
||
after_success: coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Changelog | ||
|
||
(This file may not be historically complete, as it is a recent addition to the project). | ||
|
||
|
||
## [1.0.0-alpha] - 2019-07-23 | ||
|
||
- Updated to work with CKAN 2.9.0a, e.g.: | ||
- uses toolkit wherever possible | ||
- references to Pylons removed | ||
- Standardised README, CHANGELOG, setup.py and .github files to match other Museum extensions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,121 @@ | ||
ckanext-gallery | ||
=============== | ||
<img src=".github/nhm-logo.svg" align="left" width="150px" height="100px" hspace="40"/> | ||
|
||
CKAN extension for a dataset gallery view. | ||
# ckanext-gallery | ||
|
||
Based on https://blueimp.github.io/Gallery/ | ||
[![Travis](https://img.shields.io/travis/NaturalHistoryMuseum/ckanext-gallery/master.svg?style=flat-square)](https://travis-ci.org/NaturalHistoryMuseum/ckanext-gallery) | ||
[![Coveralls](https://img.shields.io/coveralls/github/NaturalHistoryMuseum/ckanext-gallery/master.svg?style=flat-square)](https://coveralls.io/github/NaturalHistoryMuseum/ckanext-gallery) | ||
[![CKAN](https://img.shields.io/badge/ckan-2.9.0a-orange.svg?style=flat-square)](https://github.com/ckan/ckan) | ||
|
||
You can see an example at: http://data.nhm.ac.uk/dataset/collection-specimens/resource/05ff2255-c38a-40c9-b657-4ccb55ab2feb?view_id=6ba121d1-da26-4ee1-81fa-7da11e68f68e | ||
_A CKAN extension for a dataset gallery view._ | ||
|
||
|
||
# Overview | ||
|
||
Adds a gallery view for resources on a CKAN instance. Two plugins are included in this extension: `gallery` and `gallery_image`. | ||
|
||
Based on [blueimp Gallery](https://blueimp.github.io/Gallery). | ||
|
||
|
||
# Installation | ||
|
||
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` | ||
|
||
1. Clone the repository into the `src` folder: | ||
|
||
```bash | ||
cd $INSTALL_FOLDER/src | ||
git clone https://github.com/NaturalHistoryMuseum/ckanext-gallery.git | ||
``` | ||
|
||
2. Activate the virtual env: | ||
|
||
```bash | ||
. $INSTALL_FOLDER/bin/activate | ||
``` | ||
|
||
3. Install the requirements from requirements.txt: | ||
|
||
```bash | ||
cd $INSTALL_FOLDER/src/ckanext-gallery | ||
pip install -r requirements.txt | ||
``` | ||
|
||
4. Run setup.py: | ||
|
||
```bash | ||
cd $INSTALL_FOLDER/src/ckanext-gallery | ||
python setup.py develop | ||
``` | ||
|
||
5. Add 'gallery' to the list of plugins in your `$CONFIG_FILE`: | ||
|
||
```ini | ||
ckan.plugins = ... gallery | ||
``` | ||
|
||
# Configuration | ||
|
||
There's only one option that can be specified in the `.ini` file: | ||
|
||
Name|Description|Default | ||
--|---|-- | ||
`ckanext.gallery.records_per_page`|Number of images to display on a page|32 | ||
|
||
|
||
# Usage | ||
|
||
To use as a view, the 'Gallery' type should be available after installing the plugin. | ||
|
||
## Interfaces | ||
|
||
The `IGalleryImage` interface allows plugins to override settings. | ||
|
||
```python | ||
from ckan.plugins import SingletonPlugin, implements | ||
from ckanext.gallery.plugins.interfaces import IGalleryImage | ||
|
||
class YourPlugin(SingletonPlugin): | ||
implements(IGalleryImage) | ||
|
||
|
||
def image_info(self): | ||
''' | ||
Return info for this plugin. If resource type is set, | ||
only datasets of that type will be available. | ||
''' | ||
return {u'title': u'Text', | ||
u'resource_type': [u'csv', u'tsv'], | ||
u'field_type': [u'text']} | ||
|
||
|
||
def get_images(self, field_value, record, data_dict): | ||
''' | ||
Process images from a single record to return custom metadata. | ||
The field_value depends on the image field you choose. | ||
''' | ||
images = [{ | ||
u'href': field_value[u'url'], | ||
u'thumbnail': field_value[u'url'].replace(u'preview', u'thumbnail'), | ||
u'record_id': record[u'_id'] | ||
} for img in field_value] | ||
return image | ||
``` | ||
|
||
## Templates | ||
|
||
### Gallery block snippet | ||
```html+jinja | ||
{% snippet 'gallery/snippets/gallery.html', images=g.images, resource_id=res.id %} | ||
``` | ||
|
||
|
||
# Testing | ||
|
||
_Test coverage is currently extremely limited._ | ||
|
||
To run the tests, use nosetests inside your virtualenv. The `--nocapture` flag will allow you to see the debug statements. | ||
```bash | ||
nosetests --ckan --with-pylons=$TEST_CONFIG_FILE --where=$INSTALL_FOLDER/src/ckanext-gallery --nologcapture --nocapture | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
# this is a namespace package | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
# | ||
# This file is part of ckanext-gallery | ||
# Created by the Natural History Museum in London, UK | ||
|
||
try: | ||
import pkg_resources | ||
pkg_resources.declare_namespace(__name__) | ||
except ImportError: | ||
import pkgutil | ||
__path__ = pkgutil.extend_path(__path__, __name__) | ||
__path__ = pkgutil.extend_path(__path__, __name__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,13 @@ | ||
#!/usr/bin/env python | ||
# !/usr/bin/env python | ||
# encoding: utf-8 | ||
""" | ||
Created by 'bens3' on 2013-06-21. | ||
Copyright (c) 2013 'bens3'. All rights reserved. | ||
""" | ||
|
||
import sys | ||
import os | ||
# | ||
# This file is part of ckanext-gallery | ||
# Created by the Natural History Museum in London, UK | ||
|
||
|
||
def main(): | ||
pass | ||
|
||
|
||
if __name__ == '__main__': | ||
if __name__ == u'__main__': | ||
main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,28 @@ | ||
#!/usr/bin/env python | ||
# !/usr/bin/env python | ||
# encoding: utf-8 | ||
""" | ||
Created by 'bens3' on 2013-06-21. | ||
Copyright (c) 2013 'bens3'. All rights reserved. | ||
""" | ||
# | ||
# This file is part of ckanext-gallery | ||
# Created by the Natural History Museum in London, UK | ||
|
||
import ckan.plugins as p | ||
from ckan.plugins import toolkit | ||
|
||
_cache = {} | ||
|
||
|
||
def get_datastore_fields(resource_id): | ||
""" | ||
Retrieve list of dataset fields | ||
'''Retrieve list of dataset fields | ||
Checked between requests so we can quickly reuse without searching again | ||
:param resource_id: | ||
:return: | ||
""" | ||
:param resource_id: return: | ||
''' | ||
try: | ||
fields = _cache[resource_id] | ||
except KeyError: | ||
data = {'resource_id': resource_id, 'limit': 0} | ||
fields = _cache[resource_id] = p.toolkit.get_action('datastore_search')({}, data)['fields'] | ||
return fields | ||
data = { | ||
u'resource_id': resource_id, | ||
u'limit': 0 | ||
} | ||
fields = _cache[resource_id] = \ | ||
toolkit.get_action(u'datastore_search')({}, data)[u'fields'] | ||
return fields |
Oops, something went wrong.