Commit 9ba2556e authored by Denis Laxalde's avatar Denis Laxalde
Browse files

[views] Properly build CKAN URL in goto-ckan-dataset component

Factor out the URL building step from ckan_post function and use it in the
latter component.
parent cb011e37fd3c
......@@ -27,11 +27,17 @@ class CKANPostError(Exception):
"""CKAN post action error"""
def ckan_post(config, action, data=None, files=None):
def ckan_buildurl(config, path):
"""Return a full URL in the CKAN instance built from path"""
base = config['ckan-baseurl']
if not base.endswith('/'):
base += '/'
url = urljoin(base, 'api/3/action/' + action)
return urljoin(base, path)
def ckan_post(config, action, data=None, files=None):
"""Post an API request for `action` in the CKAN instance"""
url = ckan_buildurl(config, 'api/3/action/' + action)
headers = {'Authorization': config['ckan-api-key']}
if files is None:
data = json.dumps(data or {})
......@@ -16,14 +16,12 @@
"""cubicweb-ckanpublish views/forms/actions/components for web ui"""
from urlparse import urljoin
from logilab.mtconverter import xml_escape
from cubicweb.predicates import score_entity
from cubicweb.web import component
from cubes.ckanpublish.utils import ckan_post
from cubes.ckanpublish.utils import ckan_post, ckan_buildurl
_ = unicode
......@@ -55,7 +53,6 @@ class GotoCKANDatasetComponent(component.EntityCtxComponent):
def render_body(self, w):
r = self._ckan_response
config = self._cw.vreg.config
base = config['ckan-baseurl']
url = urljoin(base, 'dataset/' + xml_escape(r['name']))
url = ckan_buildurl(self._cw.vreg.config,
'dataset/' + xml_escape(r['name']))
w(u'<a target=_blank href="%s">%s<a/>' % (url, xml_escape(url)))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment