Skip to content

Commit

Permalink
Redirect if given a single string
Browse files Browse the repository at this point in the history
  • Loading branch information
Zharktas committed Aug 11, 2017
1 parent df61890 commit 895de2c
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions ckan/lib/helpers.py
Expand Up @@ -152,6 +152,11 @@ def redirect_to(*args, **kw):
toolkit.redirect_to('dataset_read', id='changed')
If given a single string as argument, this redirects without url parsing
toolkit.redirect_to('http://example.com')
toolkit.redirect_to('/dataset')
'''
if are_there_flash_messages():
kw['__no_cache__'] = True
Expand All @@ -160,15 +165,14 @@ def redirect_to(*args, **kw):
uargs = map(lambda arg: str(arg) if isinstance(arg, unicode) else arg,
args)

# Remove LANG from root_path so that we do not need to parse locales
root_path = config.get('ckan.root_path', None)
if root_path:
root_path = re.sub('/{{LANG}}', '', root_path)
# Repoze.who redirects with single strings
# which need to be parsed by url_for
exempt_urls = ['/user/logout', '/user/logged_out_redirect',
'/user/logged_in']
matching = [s for s in uargs if any(xs in s for xs in exempt_urls)]

# If args contain full url eg. http://example.com
# or url starting with root_path skip url parsing
if uargs and (is_url(uargs[0])
or (root_path and uargs[0].startswith(root_path))):
if uargs and len(uargs) is 1 and isinstance(uargs[0], basestring) \
and len(matching) is 0:
return _routes_redirect_to(uargs[0])

_url = url_for(*uargs, **kw)
Expand Down

0 comments on commit 895de2c

Please sign in to comment.