Skip to content

Commit

Permalink
Merge pull request #5395 from czpython/fixes/3.2.x/3547
Browse files Browse the repository at this point in the history
forward port of #2212 to fix #3547
  • Loading branch information
czpython committed Jun 13, 2016
2 parents cb7397c + 880832e commit 7389b8a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cms/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,19 @@ def test_toolbar_switch_urls(self):
response = self.client.get("/fr/?%s" % get_cms_setting('CMS_TOOLBAR_URL__EDIT_OFF'))
self.assertContains(response, "/fr/?%s" % get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON'), 1, 200)

def test_incorrect_slug_for_language(self):
"""
Test details view when page slug and current language don't match.
In this case we refer to the user's current language and the page slug we have for that language.
"""
create_page("home", "nav_playground.html", "en", published=True)
cms_page = create_page("stevejobs", "nav_playground.html", "en", published=True)
create_title("de", "jobs", cms_page)
cms_page.publish('de')
response = self.client.get('/de/stevejobs/')
self.assertEqual(response.status_code, 302)
self.assertRedirects(response, '/de/jobs/')


@override_settings(ROOT_URLCONF='cms.test_utils.project.urls')
class ContextTests(ClearURLs, CMSTestCase):
Expand Down
11 changes: 11 additions & 0 deletions cms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ def details(request, slug):
if not found and (not hasattr(request, 'toolbar') or not request.toolbar.redirect_url):
# There is a page object we can't find a proper language to render it
_handle_no_page(request, slug)
else:
page_path = page.get_absolute_url(language=current_language)
page_slug = page.get_path(language=current_language) or page.get_slug(language=current_language)

if slug and slug != page_slug and request.path[:len(page_path)] != page_path:
# The current language does not match it's slug.
# Redirect to the current language.
if hasattr(request, 'toolbar') and request.user.is_staff and request.toolbar.edit_mode:
request.toolbar.redirect_url = page_path
else:
return HttpResponseRedirect(page_path)

if apphook_pool.get_apphooks():
# There are apphooks in the pool. Let's see if there is one for the
Expand Down

0 comments on commit 7389b8a

Please sign in to comment.