Author: jezdez
Date: 2012-03-02 14:35:26 -0800 (Fri, 02 Mar 2012)
New Revision: 17633
Modified:
django/trunk/django/middleware/locale.py
django/trunk/tests/regressiontests/i18n/patterns/tests.py
Log:
Fixed #17817 -- Modified LocalMiddleware to use full URLs when redirecting to
i18n URLs. Thanks to Paul for keeping an eye on the standards.
Modified: django/trunk/django/middleware/locale.py
===================================================================
--- django/trunk/django/middleware/locale.py 2012-03-02 22:32:22 UTC (rev
17632)
+++ django/trunk/django/middleware/locale.py 2012-03-02 22:35:26 UTC (rev
17633)
@@ -33,9 +33,12 @@
language_path = '/%s%s' % (language, request.path_info)
if settings.APPEND_SLASH and not language_path.endswith('/'):
language_path = language_path + '/'
+
if is_valid_path(language_path, urlconf):
- return HttpResponseRedirect(
- '/%s%s' % (language, request.get_full_path()))
+ language_url = "%s://%s/%s%s" % (
+ request.is_secure() and 'https' or 'http',
+ request.get_host(), language, request.get_full_path())
+ return HttpResponseRedirect(language_url)
translation.deactivate()
patch_vary_headers(response, ('Accept-Language',))
Modified: django/trunk/tests/regressiontests/i18n/patterns/tests.py
===================================================================
--- django/trunk/tests/regressiontests/i18n/patterns/tests.py 2012-03-02
22:32:22 UTC (rev 17632)
+++ django/trunk/tests/regressiontests/i18n/patterns/tests.py 2012-03-02
22:35:26 UTC (rev 17633)
@@ -182,14 +182,12 @@
self.assertRedirects(response, '/not-prefixed/', 301)
def test_en_redirect(self):
- response = self.client.get('/account/register',
HTTP_ACCEPT_LANGUAGE='en')
+ response = self.client.get('/account/register',
HTTP_ACCEPT_LANGUAGE='en', follow=True)
# target status code of 301 because of CommonMiddleware redirecting
- self.assertRedirects(response, '/en/account/register', 302,
target_status_code=301)
+ self.assertIn(('http://testserver/en/account/register/', 301),
response.redirect_chain)
+ self.assertRedirects(response, '/en/account/register/', 302)
- response = self.client.get(response['location'])
- self.assertRedirects(response, '/en/account/register/', 301)
-
class URLRedirectWithoutTrailingSlashSettingTests(URLTestCaseBase):
"""
Tests the redirect when the requested URL doesn't end with a slash
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.