mirror of https://github.com/django/django.git
Refs #25753 -- Reset l10n cache when format settings change
Thanks Jaap Roes for the initial patch.
This commit is contained in:
parent
0a8c685447
commit
1206d7fa57
|
@ -10,6 +10,7 @@ from django.db import connections, router
|
||||||
from django.db.utils import ConnectionRouter
|
from django.db.utils import ConnectionRouter
|
||||||
from django.dispatch import Signal, receiver
|
from django.dispatch import Signal, receiver
|
||||||
from django.utils import six, timezone
|
from django.utils import six, timezone
|
||||||
|
from django.utils.formats import FORMAT_SETTINGS, reset_format_cache
|
||||||
from django.utils.functional import empty
|
from django.utils.functional import empty
|
||||||
|
|
||||||
template_rendered = Signal(providing_args=["template", "context"])
|
template_rendered = Signal(providing_args=["template", "context"])
|
||||||
|
@ -117,6 +118,12 @@ def language_changed(**kwargs):
|
||||||
trans_real.check_for_language.cache_clear()
|
trans_real.check_for_language.cache_clear()
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(setting_changed)
|
||||||
|
def localize_settings_changed(**kwargs):
|
||||||
|
if kwargs['setting'] in FORMAT_SETTINGS or kwargs['setting'] == 'USE_THOUSAND_SEPARATOR':
|
||||||
|
reset_format_cache()
|
||||||
|
|
||||||
|
|
||||||
@receiver(setting_changed)
|
@receiver(setting_changed)
|
||||||
def file_storage_changed(**kwargs):
|
def file_storage_changed(**kwargs):
|
||||||
if kwargs['setting'] == 'DEFAULT_FILE_STORAGE':
|
if kwargs['setting'] == 'DEFAULT_FILE_STORAGE':
|
||||||
|
|
|
@ -186,9 +186,6 @@ class AdminViewBasicTestCase(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.client.force_login(self.superuser)
|
self.client.force_login(self.superuser)
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
formats.reset_format_cache()
|
|
||||||
|
|
||||||
def assertContentBefore(self, response, text1, text2, failing_msg=None):
|
def assertContentBefore(self, response, text1, text2, failing_msg=None):
|
||||||
"""
|
"""
|
||||||
Testing utility asserting that text1 appears before text2 in response
|
Testing utility asserting that text1 appears before text2 in response
|
||||||
|
@ -5301,9 +5298,6 @@ class DateHierarchyTests(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.client.force_login(self.superuser)
|
self.client.force_login(self.superuser)
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
formats.reset_format_cache()
|
|
||||||
|
|
||||||
def assert_non_localized_year(self, response, year):
|
def assert_non_localized_year(self, response, year):
|
||||||
"""
|
"""
|
||||||
The year is not localized with USE_THOUSAND_SEPARATOR (#15234).
|
The year is not localized with USE_THOUSAND_SEPARATOR (#15234).
|
||||||
|
|
|
@ -731,17 +731,16 @@ class FormattingTests(SimpleTestCase):
|
||||||
even if they would be interpreted as False in a conditional test
|
even if they would be interpreted as False in a conditional test
|
||||||
(e.g. 0 or empty string) (#16938).
|
(e.g. 0 or empty string) (#16938).
|
||||||
"""
|
"""
|
||||||
with patch_formats('fr', THOUSAND_SEPARATOR='', FIRST_DAY_OF_WEEK=0):
|
with translation.override('fr'):
|
||||||
with translation.override('fr'):
|
with self.settings(USE_THOUSAND_SEPARATOR=True, THOUSAND_SEPARATOR='!'):
|
||||||
with self.settings(USE_THOUSAND_SEPARATOR=True, THOUSAND_SEPARATOR='!'):
|
self.assertEqual('\xa0', get_format('THOUSAND_SEPARATOR'))
|
||||||
self.assertEqual('', get_format('THOUSAND_SEPARATOR'))
|
# Even a second time (after the format has been cached)...
|
||||||
# Even a second time (after the format has been cached)...
|
self.assertEqual('\xa0', get_format('THOUSAND_SEPARATOR'))
|
||||||
self.assertEqual('', get_format('THOUSAND_SEPARATOR'))
|
|
||||||
|
|
||||||
with self.settings(FIRST_DAY_OF_WEEK=1):
|
with self.settings(FIRST_DAY_OF_WEEK=0):
|
||||||
self.assertEqual(0, get_format('FIRST_DAY_OF_WEEK'))
|
self.assertEqual(1, get_format('FIRST_DAY_OF_WEEK'))
|
||||||
# Even a second time (after the format has been cached)...
|
# Even a second time (after the format has been cached)...
|
||||||
self.assertEqual(0, get_format('FIRST_DAY_OF_WEEK'))
|
self.assertEqual(1, get_format('FIRST_DAY_OF_WEEK'))
|
||||||
|
|
||||||
def test_l10n_enabled(self):
|
def test_l10n_enabled(self):
|
||||||
self.maxDiff = 3000
|
self.maxDiff = 3000
|
||||||
|
@ -1161,8 +1160,8 @@ class FormattingTests(SimpleTestCase):
|
||||||
with self.settings(USE_THOUSAND_SEPARATOR=True, USE_L10N=False):
|
with self.settings(USE_THOUSAND_SEPARATOR=True, USE_L10N=False):
|
||||||
self.assertEqual(sanitize_separators('12\xa0345'), '12\xa0345')
|
self.assertEqual(sanitize_separators('12\xa0345'), '12\xa0345')
|
||||||
|
|
||||||
with patch_formats(get_language(), THOUSAND_SEPARATOR='.', DECIMAL_SEPARATOR=','):
|
with self.settings(USE_THOUSAND_SEPARATOR=True):
|
||||||
with self.settings(USE_THOUSAND_SEPARATOR=True):
|
with patch_formats(get_language(), THOUSAND_SEPARATOR='.', DECIMAL_SEPARATOR=','):
|
||||||
self.assertEqual(sanitize_separators('10.234'), '10234')
|
self.assertEqual(sanitize_separators('10.234'), '10234')
|
||||||
# Suspicion that user entered dot as decimal separator (#22171)
|
# Suspicion that user entered dot as decimal separator (#22171)
|
||||||
self.assertEqual(sanitize_separators('10.10'), '10.10')
|
self.assertEqual(sanitize_separators('10.10'), '10.10')
|
||||||
|
|
Loading…
Reference in New Issue