diff --git a/ckanext/odsh/helpers.py b/ckanext/odsh/helpers.py index d7b0d5e541cf1e661999010003eaf2bfce33fc41..60fccc73dcecfd44049a3db1f37c1421ac51c5b3 100644 --- a/ckanext/odsh/helpers.py +++ b/ckanext/odsh/helpers.py @@ -13,6 +13,8 @@ import urllib import hashlib import re from ckan.common import request +from urlparse import urlsplit, urlunsplit + get_action = logic.get_action log = logging.getLogger(__name__) @@ -215,3 +217,11 @@ def odsh_has_more_facets(facet, limit=None, exclude_active=False): def odsh_public_url(): return config.get('ckanext.odsh.public_url') + +def odsh_public_resource_url(res): + home = config.get('ckanext.odsh.public_url') + if res.get('url_type',None) == 'upload' and 'url' in res: + f = urlsplit(res['url']) + return urlunsplit((0, 0, f[2], f[3], f[4])) + else: + return res['url'] diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py index 36e9e367da3a9f7f9323043004f0ec34c7d8a787..d798c61729731a1dd458912f6948ba47c1394830 100644 --- a/ckanext/odsh/plugin.py +++ b/ckanext/odsh/plugin.py @@ -289,7 +289,8 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm 'odsh_tracking_id': odsh_helpers.odsh_tracking_id, 'odsh_tracking_url': odsh_helpers.odsh_tracking_url, 'odsh_has_more_facets': odsh_helpers.odsh_has_more_facets, - 'odsh_public_url': odsh_helpers.odsh_public_url + 'odsh_public_url': odsh_helpers.odsh_public_url, + 'odsh_public_resource_url': odsh_helpers.odsh_public_resource_url } def after_map(self, map): diff --git a/ckanext/odsh/templates/package/snippets/resource_item.html b/ckanext/odsh/templates/package/snippets/resource_item.html index 20daf85e2a72769f395c2f7d2f8d7f2719716532..cf63b5a7ba30932a882c494c31c6b0c7c29d556b 100644 --- a/ckanext/odsh/templates/package/snippets/resource_item.html +++ b/ckanext/odsh/templates/package/snippets/resource_item.html @@ -1,8 +1,8 @@ {% set url_action = 'resource_edit' if url_is_edit and can_edit else 'resource_read' %} {% set url = h.url_for(controller='package', action=url_action, id=pkg.name, resource_id=res.id) %} -{% set download = res.url or url %} -{% set res_details = h.odsh_get_resource_details(res.id) %} +{# hack for correcting slave url if resource was uploaded #} +{% set download = h.odsh_public_resource_url(res) or ulr%} <li class="resource-item" data-id="{{ res.id }}">