Skip to content

Commit

Permalink
fix redirect double root bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Mar 1, 2012
1 parent 687c5a1 commit a5cbc58
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ckan/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

def redirect_to(*args, **kw):
'''A routes.redirect_to wrapper to retain the i18n settings'''
kw['__ckan_no_root'] = True
return _redirect_to(url_for(*args, **kw))

def url(*args, **kw):
Expand Down Expand Up @@ -79,6 +80,7 @@ def _add_i18n_to_url(url_to_amend, **kw):

default_locale = False
locale = kw.pop('locale', None)
no_root = kw.pop('__ckan_no_root', False)
allowed_locales = ['default'] + i18n.get_locales()
if locale and locale not in allowed_locales:
locale = None
Expand All @@ -96,13 +98,17 @@ def _add_i18n_to_url(url_to_amend, **kw):
except TypeError:
root = ''
if default_locale:
url = url_to_amend[len(root):]
url = '%s%s' % (root, url)
url = url_to_amend
else:
# we need to strip the root from the url and the add it before
# the language specification.
url = url_to_amend[len(root):]
url = '%s/%s%s' % (root, locale, url)

# stop the root being added twice in redirects
if no_root:
url = url_to_amend[len(root):]

return url

class Message(object):
Expand Down

0 comments on commit a5cbc58

Please sign in to comment.