1
0
mirror of https://github.com/django/django.git synced 2024-12-23 01:25:58 +00:00

Fixed #26271 -- Fixed i18n_patterns resolution when no language is active

Thanks Marten Kenbeek for the report.
This commit is contained in:
Claude Paroz 2016-03-05 20:20:40 +01:00
parent 2109975e90
commit 95ca01f999
2 changed files with 5 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import functools
import re import re
from importlib import import_module from importlib import import_module
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.utils import lru_cache, six from django.utils import lru_cache, six
from django.utils.datastructures import MultiValueDict from django.utils.datastructures import MultiValueDict
@ -388,7 +389,7 @@ class LocaleRegexURLResolver(RegexURLResolver):
@property @property
def regex(self): def regex(self):
language_code = get_language() language_code = get_language() or settings.LANGUAGE_CODE
if language_code not in self._regex_dict: if language_code not in self._regex_dict:
regex_compiled = re.compile('^%s/' % language_code, re.UNICODE) regex_compiled = re.compile('^%s/' % language_code, re.UNICODE)
self._regex_dict[language_code] = regex_compiled self._regex_dict[language_code] = regex_compiled

View File

@ -2,6 +2,7 @@ from __future__ import unicode_literals
import os import os
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.http import HttpResponsePermanentRedirect from django.http import HttpResponsePermanentRedirect
from django.middleware.locale import LocaleMiddleware from django.middleware.locale import LocaleMiddleware
@ -75,6 +76,8 @@ class URLPrefixTests(URLTestCaseBase):
self.assertEqual(reverse('prefixed'), '/en/prefixed/') self.assertEqual(reverse('prefixed'), '/en/prefixed/')
with translation.override('nl'): with translation.override('nl'):
self.assertEqual(reverse('prefixed'), '/nl/prefixed/') self.assertEqual(reverse('prefixed'), '/nl/prefixed/')
with translation.override(None):
self.assertEqual(reverse('prefixed'), '/%s/prefixed/' % settings.LANGUAGE_CODE)
@override_settings(ROOT_URLCONF='i18n.patterns.urls.wrong') @override_settings(ROOT_URLCONF='i18n.patterns.urls.wrong')
def test_invalid_prefix_use(self): def test_invalid_prefix_use(self):