Skip to content

Commit

Permalink
fix broken language toggle url when there is params in current url
Browse files Browse the repository at this point in the history
  • Loading branch information
fanjinfei authored and amercader committed Jun 21, 2017
1 parent 5b1e0e5 commit 109d47c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
7 changes: 6 additions & 1 deletion ckan/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def get_site_protocol_and_host():
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.
Expand Down Expand Up @@ -307,6 +307,11 @@ def full_current_url():
return (url_for(request.environ['CKAN_CURRENT_URL'], qualified=True))


def current_url():
''' Returns current url unquoted'''
return urllib.unquote(request.environ['CKAN_CURRENT_URL'])


def lang():
''' Return the language code for the current locale eg `en` '''
return request.environ.get('CKAN_LANG')
Expand Down
3 changes: 1 addition & 2 deletions ckan/templates/snippets/language_selector.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{% set current_url = request.environ.CKAN_CURRENT_URL %}
{% set current_lang = request.environ.CKAN_LANG %}
<form class="form-inline form-select lang-select" action="{% url_for controller='util', action='redirect' %}" data-module="select-switch" method="POST">
<label for="field-lang-select">{{ _('Language') }}</label>
<select id="field-lang-select" name="url" data-module="autocomplete" data-module-dropdown-class="lang-dropdown" data-module-container-class="lang-container">
{% for locale in h.get_available_locales() %}
<option value="{% url_for current_url, locale=locale %}" {% if locale == current_lang %}selected="selected"{% endif %}>
<option value="{% url_for h.current_url(), locale=locale.short_name %}" {% if locale.identifier == current_lang %}selected="selected"{% endif %}>
{{ locale.display_name or locale.english_name }}
</option>
{% endfor %}
Expand Down
10 changes: 10 additions & 0 deletions ckan/tests/controllers/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,16 @@ def test_search_basic(self):

assert dataset1['name'] in page.body.decode('utf8')

def test_search_language_toggle(self):
dataset1 = factories.Dataset()

offset = url_for(controller='package', action='search', q=dataset1['name'])
app = self._get_test_app()
page = app.get(offset)

assert dataset1['name'] in page.body.decode('utf8')
assert ('q=' + dataset1['name']) in page.body.decode('utf8')

def test_search_sort_by_blank(self):
factories.Dataset()

Expand Down

0 comments on commit 109d47c

Please sign in to comment.