Skip to content

Commit

Permalink
[#2691] Fixes regarding previewing config options
Browse files Browse the repository at this point in the history
* Moved to the helpers function, as on the module root config options
  weren't yet set.
* Define default values, otherwise instances using old ini files won't
  get any format preview
* Namespace config options ("ckan.preview...")
* Add documentation about the config options
  • Loading branch information
amercader committed Dec 19, 2012
1 parent d09eadb commit 40f5997
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
4 changes: 2 additions & 2 deletions ckan/config/deployment.ini_tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ ckan.feeds.author_link =
#
# Set the file types that should be previewed inline (e.g. images) or directly in an iframe.

preview.direct = png jpg gif
preview.loadable = html htm rdf+xml owl+xml xml n3 n-triples turtle plain atom csv tsv rss txt json
ckan.preview.direct = png jpg gif
ckan.preview.loadable = html htm rdf+xml owl+xml xml n3 n-triples turtle plain atom csv tsv rss txt json

# Activity Streams
#
Expand Down
5 changes: 2 additions & 3 deletions ckan/lib/datapreview.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@

import ckan.plugins as p


direct_embed = config.get('preview.direct', '').split(' ')
loadable_in_iframe = config.get('preview.loadable', '').split(' ')
DEFAULT_DIRECT_EMBED = ['png', 'jpg', 'gif']
DEFAULT_LOADABLE_IFRAME = ['html', 'htm', 'rdf+xml', 'owl+xml', 'xml', 'n3', 'n-triples', 'turtle', 'plain', 'atom', 'csv', 'tsv', 'rss', 'txt', 'json']


def compare_domains(urls):
Expand Down
10 changes: 8 additions & 2 deletions ckan/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1394,14 +1394,20 @@ def resource_preview(resource, pkg_id):
resource_type=format_lower,
reason='No valid resource url has been defined.'
)
direct_embed = config.get('ckan.preview.direct', '').split()
if not direct_embed:
direct_embed = datapreview.DEFAULT_DIRECT_EMBED
loadable_in_iframe = config.get('ckan.preview.loadable', '').split()
if not loadable_in_iframe:
loadable_in_iframe = datapreview.DEFAULT_LOADABLE_IFRAME

if datapreview.can_be_previewed(data_dict):
url = url_for(controller='package', action='resource_datapreview',
resource_id=resource['id'], id=pkg_id, qualified=True)
elif format_lower in datapreview.direct_embed:
elif format_lower in direct_embed:
directly = True
url = resource['url']
elif format_lower in datapreview.loadable_in_iframe:
elif format_lower in loadable_in_iframe:
url = resource['url']
else:
log.info('No preview handler for resource type {0}'.format(format_lower))
Expand Down
21 changes: 21 additions & 0 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,27 @@ Default value: ``20``

This controls the pagination of the dataset search results page. This is the maximum number of datasets viewed per page of results.

ckan.preview.direct
^^^^^^^^^^^^^^^^^^^

Example::
ckan.preview.direct = png jpg gif

Default value: ``png jpg gif``

Defines the resource formats which should be embedded directly in an `img` tag
when previewing them.

ckan.preview.loadable
^^^^^^^^^^^^^^^^^^^^^

Example::
ckan.preview.loadable = html htm rdf+xml owl+xml xml n3 n-triples turtle plain atom csv tsv rss txt json

Default value: ``html htm rdf+xml owl+xml xml n3 n-triples turtle plain atom csv tsv rss txt json``

Defines the resource formats which should be loaded directly in an `iframe`
tag when previewing them.

Authentication Settings
-----------------------
Expand Down

0 comments on commit 40f5997

Please sign in to comment.