Skip to content

Commit

Permalink
Merge pull request #3380 from mattfullerton/image-view-configurable-f…
Browse files Browse the repository at this point in the history
…ormats

Add an ckan.preview.image_formats config option for the image viewer
  • Loading branch information
amercader committed Jan 3, 2017
2 parents d63655f + 918a32f commit 97da20e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
7 changes: 7 additions & 0 deletions ckan/config/deployment.ini_tmpl
Expand Up @@ -106,6 +106,13 @@ ckan.plugins = stats text_view image_view recline_view
# (plugins must be loaded in ckan.plugins)
ckan.views.default_views = image_view text_view recline_view

# Customize which text formats the text_view plugin will show
#ckan.preview.json_formats = json
#ckan.preview.xml_formats = xml rdf rdf+xml owl+xml atom rss
#ckan.preview.text_formats = text plain text/plain

# Customize which image formats the image_view plugin will show
#ckan.preview.image_formats = png jpeg jpg gif

## Front-End Settings
ckan.site_title = CKAN
Expand Down
7 changes: 5 additions & 2 deletions ckanext/imageview/plugin.py
Expand Up @@ -6,7 +6,7 @@
log = logging.getLogger(__name__)
ignore_empty = p.toolkit.get_validator('ignore_empty')

DEFAULT_IMAGE_FORMATS = ['png', 'jpeg', 'jpg', 'gif']
DEFAULT_IMAGE_FORMATS = 'png jpeg jpg gif'


class ImageView(p.SingletonPlugin):
Expand All @@ -17,6 +17,9 @@ class ImageView(p.SingletonPlugin):

def update_config(self, config):
p.toolkit.add_template_directory(config, 'theme/templates')
self.formats = config.get(
'ckan.preview.image_formats',
DEFAULT_IMAGE_FORMATS).split()

def info(self):
return {'name': 'image_view',
Expand All @@ -30,7 +33,7 @@ def info(self):

def can_view(self, data_dict):
return (data_dict['resource'].get('format', '').lower()
in DEFAULT_IMAGE_FORMATS)
in self.formats)

def view_template(self, context, data_dict):
return 'image_view.html'
Expand Down
19 changes: 16 additions & 3 deletions doc/maintaining/configuration.rst
Expand Up @@ -1186,7 +1186,7 @@ Example::

Default value: ``json``

JSON based resource formats that will be rendered by the Text view plugin (``text_view``)
Space-delimited list of JSON based resource formats that will be rendered by the Text view plugin (``text_view``)

.. _ckan.preview.xml_formats:

Expand All @@ -1199,7 +1199,7 @@ Example::

Default value: ``xml rdf rdf+xml owl+xml atom rss``

XML based resource formats that will be rendered by the Text view plugin (``text_view``)
Space-delimited list of XML based resource formats that will be rendered by the Text view plugin (``text_view``)

.. _ckan.preview.text_formats:

Expand All @@ -1212,7 +1212,20 @@ Example::

Default value: ``text plain text/plain``

Plain text based resource formats that will be rendered by the Text view plugin (``text_view``)
Space-delimited list of plain text based resource formats that will be rendered by the Text view plugin (``text_view``)

.. _ckan.preview.image_formats:

ckan.preview.image_formats
^^^^^^^^^^^^^^^^^^^^^^^^^^

Example::

ckan.preview.image_formats = png jpeg jpg gif

Default value: ``png jpeg jpg gif``

Space-delimited list of image-based resource formats that will be rendered by the Image view plugin (``image_view``)

.. end_resource-views
Expand Down
3 changes: 2 additions & 1 deletion doc/maintaining/data-viewer.rst
Expand Up @@ -200,7 +200,8 @@ View plugin: ``image_view``

If the resource format is a common image format like PNG, JPEG or GIF, it adds
an ``<img>`` tag pointing to the resource URL. You can provide an alternative
URL on the edit view form.
URL on the edit view form. The available formats can be configured using the
:ref:`ckan.preview.image_formats` configuration option.

Web page view
+++++++++++++
Expand Down

0 comments on commit 97da20e

Please sign in to comment.