From e7913c35fb4155aac6d79ff6e9f26f0e79a97c68 Mon Sep 17 00:00:00 2001 From: Matt Fullerton Date: Thu, 22 Dec 2016 13:28:05 +0100 Subject: [PATCH 1/4] Add an ckan.preview.image_formats config option for the image viewer --- ckanext/imageview/plugin.py | 4 +++- doc/maintaining/configuration.rst | 13 +++++++++++++ doc/maintaining/data-viewer.rst | 3 ++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ckanext/imageview/plugin.py b/ckanext/imageview/plugin.py index 329b88b4126..4d4065c88bb 100644 --- a/ckanext/imageview/plugin.py +++ b/ckanext/imageview/plugin.py @@ -17,6 +17,8 @@ class ImageView(p.SingletonPlugin): def update_config(self, config): p.toolkit.add_template_directory(config, 'theme/templates') + image_formats = config.get('ckan.preview.image_formats', '').split() + self.formats = image_formats or DEFAULT_IMAGE_FORMATS def info(self): return {'name': 'image_view', @@ -30,7 +32,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' diff --git a/doc/maintaining/configuration.rst b/doc/maintaining/configuration.rst index c9658d58796..621dd331cc6 100644 --- a/doc/maintaining/configuration.rst +++ b/doc/maintaining/configuration.rst @@ -1214,6 +1214,19 @@ Default value: ``text plain text/plain`` 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.text_formats = png jpeg jpg gif + +Default value: ``png jpeg jpg gif`` + +Image based resource formats that will be rendered by the Image view plugin (``image_view``) + .. end_resource-views Theming Settings diff --git a/doc/maintaining/data-viewer.rst b/doc/maintaining/data-viewer.rst index d0d21166e69..0051c5dc0e0 100644 --- a/doc/maintaining/data-viewer.rst +++ b/doc/maintaining/data-viewer.rst @@ -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 ```` 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 +++++++++++++ From 835a468f08463d72a247d2632fa99714e5bd6605 Mon Sep 17 00:00:00 2001 From: Matt Fullerton Date: Mon, 2 Jan 2017 11:53:47 +0100 Subject: [PATCH 2/4] Doc/Config improvements Add clarification to configuration doc that list is space delimited and do the same for text_view formats Remove type in config example (image instead of text) Add sample configs for text_view and image_view --- ckan/config/deployment.ini_tmpl | 7 +++++++ doc/maintaining/configuration.rst | 10 +++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ckan/config/deployment.ini_tmpl b/ckan/config/deployment.ini_tmpl index ee59c86e329..3fdafe747e2 100644 --- a/ckan/config/deployment.ini_tmpl +++ b/ckan/config/deployment.ini_tmpl @@ -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 diff --git a/doc/maintaining/configuration.rst b/doc/maintaining/configuration.rst index 621dd331cc6..0d1fc1a76ff 100644 --- a/doc/maintaining/configuration.rst +++ b/doc/maintaining/configuration.rst @@ -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: @@ -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: @@ -1212,7 +1212,7 @@ 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: @@ -1221,11 +1221,11 @@ ckan.preview.image_formats Example:: - ckan.preview.text_formats = png jpeg jpg gif + ckan.preview.image_formats = png jpeg jpg gif Default value: ``png jpeg jpg gif`` -Image based resource formats that will be rendered by the Image view plugin (``image_view``) +Space-delimited list of image-based resource formats that will be rendered by the Image view plugin (``image_view``) .. end_resource-views From 477f4a0f4a4ed321f3fa90c6064960dd2cb0fab8 Mon Sep 17 00:00:00 2001 From: Matt Fullerton Date: Mon, 2 Jan 2017 21:38:54 +0100 Subject: [PATCH 3/4] Respect a user's right to provide no image formats via the config --- ckanext/imageview/plugin.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ckanext/imageview/plugin.py b/ckanext/imageview/plugin.py index 4d4065c88bb..6f0d2ebdb5a 100644 --- a/ckanext/imageview/plugin.py +++ b/ckanext/imageview/plugin.py @@ -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): @@ -17,8 +17,7 @@ class ImageView(p.SingletonPlugin): def update_config(self, config): p.toolkit.add_template_directory(config, 'theme/templates') - image_formats = config.get('ckan.preview.image_formats', '').split() - self.formats = image_formats or DEFAULT_IMAGE_FORMATS + self.formats = config.get('ckan.preview.image_formats', DEFAULT_IMAGE_FORMATS).split() def info(self): return {'name': 'image_view', From 918a32f79b994ce54a31a607be98593000566fd8 Mon Sep 17 00:00:00 2001 From: Matt Fullerton Date: Tue, 3 Jan 2017 13:29:00 +0100 Subject: [PATCH 4/4] Fix for pep8 --- ckanext/imageview/plugin.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ckanext/imageview/plugin.py b/ckanext/imageview/plugin.py index 6f0d2ebdb5a..6c44431f74e 100644 --- a/ckanext/imageview/plugin.py +++ b/ckanext/imageview/plugin.py @@ -17,7 +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() + self.formats = config.get( + 'ckan.preview.image_formats', + DEFAULT_IMAGE_FORMATS).split() def info(self): return {'name': 'image_view',