diff --git a/ckanext/geodatagov/helpers.py b/ckanext/geodatagov/helpers.py index b8e89978..1c699a44 100644 --- a/ckanext/geodatagov/helpers.py +++ b/ckanext/geodatagov/helpers.py @@ -1,4 +1,8 @@ +import urllib import logging + +from pylons import config + from ckan import plugins as p from ckan.lib import helpers as h @@ -72,3 +76,27 @@ def get_harvest_source_link(package_dict): return p.toolkit.literal(link) return '' + +def resource_preview_custom(resource, pkg_id): + + viewer_url = config.get('ckanext.geodatagov.spatial_preview.url') + formats = config.get('ckanext.geodatagov.spatial_preview.formats', 'wms kml kmz').strip().split(' ') + + if viewer_url and resource.get('url') and resource.get('format','').lower() in formats: + params= { + 'url': resource['url'], + 'serviceType': resource['format'].lower(), + } + if resource.get('default_srs'): + params['srs'] = resource['default_srs'] + + url = '{viewer_url}?{params}'.format( + viewer_url=viewer_url, + params=urllib.urlencode(params)) + + return p.toolkit.render_snippet("dataviewer/snippets/data_preview.html", + data={'embed': False, + 'resource_url': url, + 'raw_resource_url': resource['url']}) + + return h.resource_preview(resource, pkg_id) diff --git a/ckanext/geodatagov/plugins.py b/ckanext/geodatagov/plugins.py index 715a55b5..3b778022 100644 --- a/ckanext/geodatagov/plugins.py +++ b/ckanext/geodatagov/plugins.py @@ -198,6 +198,7 @@ def get_helpers(self): 'get_harvest_source_link': geodatagov_helpers.get_harvest_source_link, 'get_validation_profiles': geodatagov_helpers.get_validation_profiles, 'get_collection_package': geodatagov_helpers.get_collection_package, + 'resource_preview_custom': geodatagov_helpers.resource_preview_custom, } ## IActions diff --git a/ckanext/geodatagov/templates/package/resource_read.html b/ckanext/geodatagov/templates/package/resource_read.html new file mode 100644 index 00000000..e61ab527 --- /dev/null +++ b/ckanext/geodatagov/templates/package/resource_read.html @@ -0,0 +1,5 @@ +{% ckan_extends %} + +{% block data_preview %} + {{ h.resource_preview_custom(c.resource, c.package.id) }} +{% endblock %}