Skip to content

Commit

Permalink
[#45] Hook into the custom spatial previewer
Browse files Browse the repository at this point in the history
A custom helper function checks if the format is one of the ones
supported by the external viewer maintained by GMU. The viewer URL and
the supported formats can be defined via config options.

ckanext.geodatagov.spatial_preview.url
ckanext.geodatagov.spatial_preview.formats

Support for a future default_srs parameter has been added.
  • Loading branch information
amercader committed Apr 3, 2013
1 parent b97a4db commit eb694b9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ckanext/geodatagov/helpers.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
1 change: 1 addition & 0 deletions ckanext/geodatagov/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions ckanext/geodatagov/templates/package/resource_read.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% ckan_extends %}

{% block data_preview %}
{{ h.resource_preview_custom(c.resource, c.package.id) }}
{% endblock %}

0 comments on commit eb694b9

Please sign in to comment.