Commits

Carl Meyer  committed 141054b

Fixed middleware redirection with script prefix. Fixes #10

  • Participants
  • Parent commits 09b997e

Comments (0)

Files changed (3)

File docs/history.rst

 ---------
 
 Tip: (unreleased)
-  * Add ``localeurl_future`` template tag library to provide ``locale_url`` tag
-    that wraps the new Django ``url`` tag to allow using the new syntax and
+  * Fixed middleware redirection when there is a script
+    prefix. Fixes #10. Thanks iro for report and draft patch.
+  * Added ``localeurl_future`` template tag library to provide ``locale_url``
+    tag that wraps the new Django ``url`` tag to allow using the new syntax and
     avoid deprecation warnings under Django 1.3. Fixes #17. Thanks Fabian
     Büchler for the report.
-  * Account for reverse() receiving kwargs=None. Fixes #18. Thanks Alexander
+  * Accounted for reverse() receiving kwargs=None. Fixes #18. Thanks Alexander
     Clausen for report and tests, Joel Ryan for draft patch.
-  * Prevent change_locale view from stripping query params from ``next``.
+  * Prevented change_locale view from stripping query params from ``next``.
     Fixes #7. Thanks Sverre Johansen.
 
 Release 1.4: (2010-03-19)

File localeurl/middleware.py

                         request.META.get('HTTP_ACCEPT_LANGUAGE', ''))])
             if accept_langs:
                 locale = accept_langs[0]
-        locale_path = utils.locale_path(path, locale)
-        if locale_path != request.path_info:
+        locale_url = utils.locale_url(path, locale)
+        if locale_url != request.path_info:
             if request.META.get("QUERY_STRING", ""):
-                locale_path = "%s?%s" % (locale_path,
+                locale_url = "%s?%s" % (locale_url,
                         request.META['QUERY_STRING'])
-            return HttpResponsePermanentRedirect(locale_path)
+            return HttpResponsePermanentRedirect(locale_url)
         request.path_info = path
         if not locale:
             try:

File localeurl/tests/__init__.py

         self.assertEqual('/test/independent/?foo=bar', r2['Location'])
 
 
+    def test_redirect_with_script_prefix(self):
+        previous_script_prefix = urlresolvers.get_script_prefix()
+        urlresolvers.set_script_prefix('/prefix/')
+
+        r1 = self.request_factory.get('/nl-be/test/independent/')
+        r2 = self.middleware.process_request(r1)
+        self.assertEqual(301, r2.status_code)
+        self.assertEqual('/prefix/test/independent/', r2['Location'])
+
+        urlresolvers.set_script_prefix(previous_script_prefix)
+
+
     def test_check_accept_lang(self):
         self.settings_manager.set(LOCALEURL_USE_ACCEPT_LANGUAGE=True)
         reload(localeurl_settings)