Fixed #14824 -- Corrected the handling of formats when USE_L10N is disabled. Thanks to nullie for the report and initial patch, and to idle for the separate report with helpful debug info.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15404 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
987fd51176
commit
d44fb0557a
|
@ -14,11 +14,21 @@ from django.utils.safestring import mark_safe
|
||||||
_format_cache = {}
|
_format_cache = {}
|
||||||
_format_modules_cache = {}
|
_format_modules_cache = {}
|
||||||
|
|
||||||
|
def reset_format_cache():
|
||||||
|
"""Clear any cached formats.
|
||||||
|
|
||||||
|
This method is provided primarily for testing purposes,
|
||||||
|
so that the effects of cached formats can be removed.
|
||||||
|
"""
|
||||||
|
global _format_cache, _format_modules_cache
|
||||||
|
_format_cache = {}
|
||||||
|
_format_modules_cache = {}
|
||||||
|
|
||||||
def iter_format_modules(lang):
|
def iter_format_modules(lang):
|
||||||
"""
|
"""
|
||||||
Does the heavy lifting of finding format modules.
|
Does the heavy lifting of finding format modules.
|
||||||
"""
|
"""
|
||||||
if check_for_language(lang) or settings.USE_L10N:
|
if check_for_language(lang):
|
||||||
format_locations = ['django.conf.locale.%s']
|
format_locations = ['django.conf.locale.%s']
|
||||||
if settings.FORMAT_MODULE_PATH:
|
if settings.FORMAT_MODULE_PATH:
|
||||||
format_locations.append(settings.FORMAT_MODULE_PATH + '.%s')
|
format_locations.append(settings.FORMAT_MODULE_PATH + '.%s')
|
||||||
|
|
|
@ -7,7 +7,7 @@ from django.utils import importlib
|
||||||
from django.utils.translation import check_for_language, activate, to_locale, get_language
|
from django.utils.translation import check_for_language, activate, to_locale, get_language
|
||||||
from django.utils.text import javascript_quote
|
from django.utils.text import javascript_quote
|
||||||
from django.utils.encoding import smart_unicode
|
from django.utils.encoding import smart_unicode
|
||||||
from django.utils.formats import get_format_modules
|
from django.utils.formats import get_format_modules, get_format
|
||||||
|
|
||||||
def set_language(request):
|
def set_language(request):
|
||||||
"""
|
"""
|
||||||
|
@ -49,10 +49,7 @@ def get_formats():
|
||||||
result = {}
|
result = {}
|
||||||
for module in [settings] + get_format_modules(reverse=True):
|
for module in [settings] + get_format_modules(reverse=True):
|
||||||
for attr in FORMAT_SETTINGS:
|
for attr in FORMAT_SETTINGS:
|
||||||
try:
|
result[attr] = get_format(attr)
|
||||||
result[attr] = getattr(module, attr)
|
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
src = []
|
src = []
|
||||||
for k, v in result.items():
|
for k, v in result.items():
|
||||||
if isinstance(v, (basestring, int)):
|
if isinstance(v, (basestring, int)):
|
||||||
|
|
|
@ -48,12 +48,18 @@ class AdminViewBasicTest(TestCase):
|
||||||
urlbit = 'admin'
|
urlbit = 'admin'
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.old_language_code = settings.LANGUAGE_CODE
|
self.old_USE_I18N = settings.LANGUAGE_CODE
|
||||||
|
self.old_USE_L10N = settings.USE_L10N
|
||||||
|
self.old_LANGUAGE_CODE = settings.LANGUAGE_CODE
|
||||||
self.client.login(username='super', password='secret')
|
self.client.login(username='super', password='secret')
|
||||||
|
settings.USE_I18N = True
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
settings.LANGUAGE_CODE = self.old_language_code
|
settings.USE_I18N = self.old_USE_I18N
|
||||||
|
settings.USE_L10N = self.old_USE_L10N
|
||||||
|
settings.LANGUAGE_CODE = self.old_LANGUAGE_CODE
|
||||||
self.client.logout()
|
self.client.logout()
|
||||||
|
formats.reset_format_cache()
|
||||||
|
|
||||||
def testTrailingSlashRequired(self):
|
def testTrailingSlashRequired(self):
|
||||||
"""
|
"""
|
||||||
|
@ -351,22 +357,42 @@ class AdminViewBasicTest(TestCase):
|
||||||
if the default language is non-English but the selected language
|
if the default language is non-English but the selected language
|
||||||
is English. See #13388 and #3594 for more details.
|
is English. See #13388 and #3594 for more details.
|
||||||
"""
|
"""
|
||||||
settings.LANGUAGE_CODE = 'fr'
|
try:
|
||||||
activate('en-us')
|
settings.LANGUAGE_CODE = 'fr'
|
||||||
response = self.client.get('/test_admin/admin/jsi18n/')
|
activate('en-us')
|
||||||
self.assertNotContains(response, 'Choisir une heure')
|
response = self.client.get('/test_admin/admin/jsi18n/')
|
||||||
deactivate()
|
self.assertNotContains(response, 'Choisir une heure')
|
||||||
|
finally:
|
||||||
|
deactivate()
|
||||||
|
|
||||||
def testI18NLanguageNonEnglishFallback(self):
|
def testI18NLanguageNonEnglishFallback(self):
|
||||||
"""
|
"""
|
||||||
Makes sure that the fallback language is still working properly
|
Makes sure that the fallback language is still working properly
|
||||||
in cases where the selected language cannot be found.
|
in cases where the selected language cannot be found.
|
||||||
"""
|
"""
|
||||||
settings.LANGUAGE_CODE = 'fr'
|
try:
|
||||||
activate('none')
|
settings.LANGUAGE_CODE = 'fr'
|
||||||
response = self.client.get('/test_admin/admin/jsi18n/')
|
activate('none')
|
||||||
self.assertContains(response, 'Choisir une heure')
|
response = self.client.get('/test_admin/admin/jsi18n/')
|
||||||
deactivate()
|
self.assertContains(response, 'Choisir une heure')
|
||||||
|
finally:
|
||||||
|
deactivate()
|
||||||
|
|
||||||
|
def testL10NDeactivated(self):
|
||||||
|
"""
|
||||||
|
Check if L10N is deactivated, the Javascript i18n view doesn't
|
||||||
|
return localized date/time formats. Refs #14824.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
settings.LANGUAGE_CODE = 'ru'
|
||||||
|
settings.USE_L10N = False
|
||||||
|
activate('ru')
|
||||||
|
response = self.client.get('/test_admin/admin/jsi18n/')
|
||||||
|
self.assertNotContains(response, '%d.%m.%Y %H:%M:%S')
|
||||||
|
self.assertContains(response, '%Y-%m-%d %H:%M:%S')
|
||||||
|
finally:
|
||||||
|
deactivate()
|
||||||
|
|
||||||
|
|
||||||
def test_disallowed_filtering(self):
|
def test_disallowed_filtering(self):
|
||||||
self.assertRaises(SuspiciousOperation,
|
self.assertRaises(SuspiciousOperation,
|
||||||
|
|
Loading…
Reference in New Issue