Skip to content

Commit

Permalink
Renamed helper to get_site_protocol_and_host and added docstring
Browse files Browse the repository at this point in the history
Conflicts:
	ckan/lib/helpers.py
  • Loading branch information
Stefan Oderbolz authored and wardi committed May 27, 2016
1 parent ee5101e commit 3903952
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion ckan/lib/helpers.py
Expand Up @@ -109,6 +109,28 @@ def url(*args, **kw):
return _local_url(my_url, locale=locale, **kw)


def get_site_protocol_and_host():
'''Return the protocol and host of the configured `ckan.site_url`.
This is needed to generate valid, full-qualified URLs.
If `ckan.site_url` is set like this::
ckan.site_url = http://example.com
Then this function would return a tuple `('http', 'example.com')`
If the setting is missing, `(None, None)` is returned instead.
'''
site_url = config.get('ckan.site_url', None)
if site_url is not None:
parsed_url = urlparse.urlparse(site_url)
return (
parsed_url.scheme.encode('utf-8'),
parsed_url.netloc.encode('utf-8')
)
return (None, None)


def url_for(*args, **kw):
'''Return the URL for the given controller, action, id, etc.
Expand Down Expand Up @@ -221,7 +243,11 @@ def _local_url(url_to_amend, **kw):
root = ''
if kw.get('qualified', False):
# if qualified is given we want the full url ie http://...
root = _routes_default_url_for('/', qualified=True)[:-1]
protocol, host = get_site_protocol_and_host()
root = _routes_default_url_for('/',
qualified=True,
host=host,
protocol=protocol)[:-1]
# ckan.root_path is defined when we have none standard language
# position in the url
root_path = config.get('ckan.root_path', None)
Expand Down

0 comments on commit 3903952

Please sign in to comment.