Skip to content

Commit

Permalink
fix ckan.root_path
Browse files Browse the repository at this point in the history
The language selector is passing a babel Locale object but
_add_i18n_to_url expects a str.
  • Loading branch information
Marc Fortier authored and amercader committed Feb 14, 2017
1 parent e5a23be commit e92596a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 1 addition & 2 deletions ckan/lib/helpers.py
Expand Up @@ -11,7 +11,6 @@
import re
import os
import urllib
import urlparse
import pprint
import copy
import urlparse
Expand Down Expand Up @@ -274,7 +273,7 @@ def _add_i18n_to_url(url_to_amend, **kw):
if default_locale:
root_path = re.sub('/{{LANG}}', '', root_path)
else:
root_path = re.sub('{{LANG}}', locale, root_path)
root_path = re.sub('{{LANG}}', str(locale), root_path)
# make sure we don't have a trailing / on the root
if root_path[-1] == '/':
root_path = root_path[:-1]
Expand Down
9 changes: 9 additions & 0 deletions ckan/tests/lib/test_helpers.py
@@ -1,5 +1,6 @@
import nose
import i18n
from babel import Locale

import ckan.lib.helpers as h
import ckan.exceptions
Expand Down Expand Up @@ -74,6 +75,14 @@ def test_url_for_with_locale(self):
locale='de')
eq_(generated_url, url)

@helpers.change_config('ckan.site_url', 'http://example.com')
@helpers.change_config('ckan.root_path', '/foo/{{LANG}}')
def test_url_for_with_locale_object(self):
url = '/foo/de/dataset/my_dataset'
generated_url = h.url_for('/dataset/my_dataset',
locale=Locale('de'))
eq_(generated_url, url)

@helpers.change_config('ckan.site_url', 'http://example.com')
def test_url_for_not_qualified(self):
url = '/dataset/my_dataset'
Expand Down

0 comments on commit e92596a

Please sign in to comment.