Skip to content

Commit

Permalink
Merge branch 'master' into enhancement-1792-api-logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Mar 1, 2012
2 parents 9ecdaea + 05d8800 commit 328f8c9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion ckan/controllers/webstore.py
Expand Up @@ -8,7 +8,8 @@ def _make_redirect(self, id, url=''):
index_name = 'ckan-%s' % g.site_id
query_string = request.environ['QUERY_STRING']
redirect = "/elastic/%s/%s%s?%s" % (index_name, id, url, query_string)
response.headers['X-Accel-Redirect'] = redirect
# headers must be ascii strings
response.headers['X-Accel-Redirect'] = str(redirect)

def read(self, id, url=''):
context = {'model': model, 'session': model.Session,
Expand Down
14 changes: 12 additions & 2 deletions ckan/lib/helpers.py
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 All @@ -49,9 +50,12 @@ def url(*args, **kw):
return _add_i18n_to_url(my_url, locale=locale, **kw)

def url_for(*args, **kw):

"""Create url adding i18n information if selected
wrapper for routes.url_for"""
locale = kw.pop('locale', None)
# remove __ckan_no_root and add after to not pollute url
no_root = kw.pop('__ckan_no_root', False)
# routes will get the wrong url for APIs if the ver is not provided
if kw.get('controller') == 'api':
ver = kw.get('ver')
Expand All @@ -60,6 +64,7 @@ def url_for(*args, **kw):
# fix ver to include the slash
kw['ver'] = '/%s' % ver
my_url = _routes_default_url_for(*args, **kw)
kw['__ckan_no_root'] = no_root
return _add_i18n_to_url(my_url, locale=locale, **kw)

def url_for_static(*args, **kw):
Expand All @@ -79,6 +84,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 +102,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
2 changes: 1 addition & 1 deletion ckan/templates/user/layout.html
Expand Up @@ -22,7 +22,7 @@
<py:if test="not c.id">
<ul class="tabbed">
<li py:attrs="{'class':'current-tab'} if c.action=='login' else {}"><a href="${h.url_for(controller='user', action='login')}">Login</a></li>
<li py:attrs="{'class':'current-tab'} if c.action=='register' else {}"><a href="${h.url_for('register')}">Register Account</a></li>
<li py:attrs="{'class':'current-tab'} if c.action=='register' else {}"><a href="${h.url_for(controller='user', action='register')}">Register Account</a></li>
</ul>
</py:if>
</py:if>
Expand Down

0 comments on commit 328f8c9

Please sign in to comment.