diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index 3b1296580d3..1e8878b3ea8 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -1328,6 +1328,14 @@ def resource_preview(resource, pkg_id): data_dict = {'resource': resource, 'package': None} + if not resource['url']: + log.info('No url for resource {0} defined.'.format(resource['id'])) + return snippet( + "dataviewer/snippets/no_preview.html", + resource_type=format_lower, + reason='No valid resource url has been defined.' + ) + if _can_be_previewed(data_dict): url = url_for(controller='package', action='resource_datapreview', resource_id=resource['id'], id=pkg_id, qualified=True) diff --git a/ckan/templates/dataviewer/snippets/no_preview.html b/ckan/templates/dataviewer/snippets/no_preview.html index 073dda4f7cf..77403152c2d 100644 --- a/ckan/templates/dataviewer/snippets/no_preview.html +++ b/ckan/templates/dataviewer/snippets/no_preview.html @@ -5,8 +5,12 @@

{{ _('This resource cannot be previewed.') }}

More details...
- {% set t = ''|safe + resource_type + ''|safe %} - {{ gettext('No handler defined for data type: %(type)s.', type=t) }} + {% if reason %} + {{_(reason)}} + {% else %} + {% set t = ''|safe + resource_type + ''|safe %} + {{ gettext('No handler defined for data type: %(type)s.', type=t) }} + {% endif %}
diff --git a/setup.py b/setup.py index 1be32dbdf5e..c32fecfd1e8 100644 --- a/setup.py +++ b/setup.py @@ -119,10 +119,10 @@ organizations_dataset=ckanext.organizations.forms:OrganizationDatasetForm datastore=ckanext.datastore.plugin:DatastorePlugin test_tag_vocab_plugin=ckanext.test_tag_vocab_plugin:MockVocabTagsPlugin + resourceproxy=ckanext.resourceproxy.plugin:ResourceProxy json_preview=ckanext.jsonpreview.plugin:JsonPreview pdf_preview=ckanext.pdfpreview.plugin:PdfPreview recline_preview=ckanext.reclinepreview.plugin:ReclinePreview - resourceproxy=ckanext.resourceproxy.plugin:ResourceProxy [ckan.system_plugins] domain_object_mods = ckan.model.modification:DomainObjectModificationExtension