Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
Reapply fix for bug 723242 branched from mdn.
Browse files Browse the repository at this point in the history
  • Loading branch information
ubernostrum committed Feb 23, 2012
1 parent df04432 commit d5385d8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
17 changes: 17 additions & 0 deletions apps/wiki/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ def _create_en_and_de_docs(self):
de_rev.save()
return en_doc, de_doc

def test_ui_locale(self):
"""Bug 723242: make sure wiki redirects insert the correct UI
locale in the URL, so that the locale middleware doesn't have
to redirect again."""
en = settings.WIKI_DEFAULT_LANGUAGE
target = document(title='Locale Redirect Test Target',
html='<p>Locale Redirect Test Target</p>',
locale=en)
target.save()
source = document(title='Locale Redirect Test Document',
html='REDIRECT <a class="redirect" href="/docs/en/locale-redirect-test-target/">Locale Redirect Test Target</a>',
locale=en)
source.save()
url = reverse('wiki.document', args=[source.slug], locale=en)
response = self.client.get(url, follow=False)
self.assertEqual(response.status_code, 302)
assert ('/%s/docs/' % en) in response['Location']

class ViewTests(TestCaseBase):
fixtures = ['test_users.json', 'wiki/documents.json']
Expand Down
8 changes: 7 additions & 1 deletion apps/wiki/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from access.decorators import permission_required, login_required
from sumo.helpers import urlparams
from sumo.urlresolvers import reverse
from sumo.urlresolvers import Prefixer, reverse
from sumo.utils import paginate, smart_int
from wiki import DOCUMENTS_PER_PAGE
from wiki.events import (EditDocumentEvent, ReviewableRevisionInLocaleEvent,
Expand Down Expand Up @@ -127,6 +127,12 @@ def document(request, document_slug):
if redirect_url:
url = urlparams(redirect_url, query_dict=request.GET,
redirectslug=doc.slug, redirectlocale=doc.locale)
# We want to make sure the UI locale is preserved in this
# redirect, so that the locale middleware doesn't have to
# redirect again afterward. Simplest way is just to do what
# the locale middleware would be doing.
prefixer = Prefixer(request=request)
url = prefixer.fix(url)
return HttpResponseRedirect(url)

# Get "redirected from" doc if we were redirected:
Expand Down

0 comments on commit d5385d8

Please sign in to comment.