Skip to content

Commit

Permalink
Handle case where no url has been defined
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Nov 2, 2012
1 parent a13f102 commit af7716b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
8 changes: 8 additions & 0 deletions ckan/lib/helpers.py
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions ckan/templates/dataviewer/snippets/no_preview.html
Expand Up @@ -5,8 +5,12 @@ <h4 class="pull-left">{{ _('This resource cannot be previewed.') }} </h4>
<i class="icon-info-sign"></i> More details...
</button>
<div id="demo" class="collapse">
{% set t = '<code>'|safe + resource_type + '</code>'|safe %}
{{ gettext('No handler defined for data type: %(type)s.', type=t) }}
{% if reason %}
{{_(reason)}}
{% else %}
{% set t = '<code>'|safe + resource_type + '</code>'|safe %}
{{ gettext('No handler defined for data type: %(type)s.', type=t) }}
{% endif %}
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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
Expand Down

0 comments on commit af7716b

Please sign in to comment.