Ticket #27402: locale_404_bug_with_test.diff

File locale_404_bug_with_test.diff, 2.1 KB (added by Hovi, 8 years ago)
  • django/middleware/locale.py

    diff --git a/django/middleware/locale.py b/django/middleware/locale.py
    index 65a3893..0b32d78 100644
    a b class LocaleMiddleware(MiddlewareMixin):  
    3737
    3838        if response.status_code == 404 and not language_from_path and i18n_patterns_used:
    3939            language_path = '/%s%s' % (language, request.path_info)
     40            if i18n_patterns_used and not prefixed_default_language and str(language) == str(settings.LANGUAGE_CODE):
     41                language_path = '/%s' % (request.path_info)
    4042            path_valid = is_valid_path(language_path, urlconf)
    4143            path_needs_slash = (
    4244                not path_valid and (
    class LocaleMiddleware(MiddlewareMixin):  
    4446                    is_valid_path('%s/' % language_path, urlconf)
    4547                )
    4648            )
    47 
    4849            if path_valid or path_needs_slash:
    4950                script_prefix = get_script_prefix()
    5051                # Insert language after the script prefix and before the
  • tests/i18n/tests.py

    diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py
    index 717150d..d82cec2 100644
    a b class UnprefixedDefaultLanguageTests(SimpleTestCase):  
    18391839        with self.assertRaisesMessage(AssertionError, "Unexpected kwargs for i18n_patterns(): {'foo':"):
    18401840            i18n_patterns(object(), foo='bar')
    18411841
     1842    def test_404_page_no_default_language_redirect(self):
     1843        response = self.client.get('/non-existent-page', follow=False)
     1844        self.assertEqual(response.status_code, 404)
     1845
    18421846
    18431847@override_settings(
    18441848    USE_I18N=True,
  • tests/i18n/urls_default_unprefixed.py

    diff --git a/tests/i18n/urls_default_unprefixed.py b/tests/i18n/urls_default_unprefixed.py
    index 8cadbfa..439234a 100644
    a b from django.utils.translation import ugettext_lazy as _  
    55
    66urlpatterns = i18n_patterns(
    77    url(r'^simple/$', lambda r: HttpResponse(_("Yes"))),
     8    url(r'^(?P<group1>.+)/(?P<group2>.+)/$', lambda r: HttpResponse(_("Group1-Group2"))),
    89    prefix_default_language=False,
    910)
Back to Top