Skip to content

Commit

Permalink
Merge 18c1810 into a1c8fdb
Browse files Browse the repository at this point in the history
  • Loading branch information
alycejenni committed Jun 7, 2019
2 parents a1c8fdb + 18c1810 commit 4e2b7e8
Show file tree
Hide file tree
Showing 15 changed files with 301 additions and 225 deletions.
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: python
python:
- "2.7"
# command to install dependencies
install:
- "pip install -e ."
- "pip install -r requirements.txt"
- "pip install -r dev_requirements.txt"
# command to run tests
script: coverage run --source=ckanext-gallery setup.py nosetests
after_success: coveralls
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ckanext-gallery
===============

[![Travis branch](https://img.shields.io/travis/NaturalHistoryMuseum/ckanext-gallery/master.svg?style=flat-square)](https://travis-ci.org/NaturalHistoryMuseum/ckanext-gallery) [![Coveralls github branch](https://img.shields.io/coveralls/github/NaturalHistoryMuseum/ckanext-gallery/master.svg?style=flat-square)](https://coveralls.io/github/NaturalHistoryMuseum/ckanext-gallery)

CKAN extension for a dataset gallery view.

Based on https://blueimp.github.io/Gallery/
Expand Down
7 changes: 6 additions & 1 deletion ckanext/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# 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__)
Expand Down
9 changes: 7 additions & 2 deletions ckanext/gallery/__init__.py
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__)
15 changes: 5 additions & 10 deletions ckanext/gallery/lib/__init__.py
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()

32 changes: 18 additions & 14 deletions ckanext/gallery/lib/helpers.py
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
29 changes: 12 additions & 17 deletions ckanext/gallery/logic/validators.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
#!/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 ckan.plugins as p
from ckan.common import _
#
# This file is part of ckanext-gallery
# Created by the Natural History Museum in London, UK

from ckanext.gallery.lib.helpers import get_datastore_fields

Invalid = p.toolkit.Invalid
from ckan.plugins import toolkit


def is_datastore_field(value, context):
'''
Make sure this field is an actual datastore field
'''Make sure this field is an actual datastore field
:param value:
:param context:
:raises: ckan.lib.navl.dictization_functions.Invalid for other
inputs or non-whole values
'''
fields = get_datastore_fields(context['resource'].id)
fields = get_datastore_fields(toolkit.c.resource.get(u'id'))
for field in fields:
if field['id'] in value:
if field[u'id'] in value:
return value
raise Invalid(_('Field {0} not in datastore'.format(value)))

raise toolkit.Invalid(toolkit._(u'Field {0} not in datastore'.format(value)))
15 changes: 5 additions & 10 deletions ckanext/gallery/plugins/__init__.py
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()

Loading

0 comments on commit 4e2b7e8

Please sign in to comment.