From 676bd084f2509f4201561d5c77ed4ecbd157bfa0 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Thu, 9 Sep 2021 07:42:05 +0200 Subject: [PATCH] Fixed #32873 -- Deprecated settings.USE_L10N. Co-authored-by: Mariusz Felisiak --- django/conf/__init__.py | 34 +++++++++ django/conf/global_settings.py | 2 +- django/conf/locale/en/formats.py | 46 +++++++++--- .../project_name/settings.py-tpl | 2 - django/utils/formats.py | 12 ++- docs/internals/deprecation.txt | 2 + docs/ref/settings.txt | 13 +++- docs/releases/1.10.txt | 2 +- docs/releases/1.2.txt | 2 +- docs/releases/2.0.txt | 2 +- docs/releases/3.2.txt | 2 +- docs/releases/4.0.txt | 21 +++++- docs/topics/i18n/formatting.txt | 16 ++-- docs/topics/i18n/timezones.txt | 6 -- docs/topics/i18n/translation.txt | 6 -- tests/admin_inlines/tests.py | 2 +- tests/admin_utils/test_logentry.py | 1 - tests/admin_utils/tests.py | 4 +- tests/admin_views/test_actions.py | 2 +- tests/admin_views/tests.py | 14 ++-- tests/admin_widgets/tests.py | 4 +- tests/deprecation/test_use_l10n.py | 43 +++++++++++ .../forms_tests/field_tests/test_datefield.py | 5 +- .../field_tests/test_decimalfield.py | 15 +++- .../field_tests/test_floatfield.py | 15 +++- tests/forms_tests/tests/test_input_formats.py | 7 +- .../test_checkboxselectmultiple.py | 2 +- .../widget_tests/test_dateinput.py | 2 - .../widget_tests/test_datetimeinput.py | 23 ++++-- .../widget_tests/test_nullbooleanselect.py | 2 - .../widget_tests/test_numberinput.py | 2 +- .../widget_tests/test_radioselect.py | 2 +- tests/forms_tests/widget_tests/test_select.py | 2 +- .../widget_tests/test_selectdatewidget.py | 11 ++- .../test_splithiddendatetimewidget.py | 2 - .../widget_tests/test_timeinput.py | 2 - tests/gis_tests/test_geoforms.py | 2 +- tests/humanize_tests/tests.py | 10 +-- tests/i18n/tests.py | 75 +++++++++++++------ tests/settings_tests/tests.py | 10 +-- tests/sitemaps_tests/test_http.py | 2 +- .../template_tests/filter_tests/test_date.py | 8 +- .../filter_tests/test_filesizeformat.py | 2 +- .../template_tests/filter_tests/test_time.py | 3 +- tests/timezones/tests.py | 30 +++++++- tests/utils_tests/test_numberformat.py | 3 +- tests/view_tests/tests/test_debug.py | 2 +- tests/view_tests/tests/test_i18n.py | 6 +- 48 files changed, 335 insertions(+), 148 deletions(-) create mode 100644 tests/deprecation/test_use_l10n.py diff --git a/django/conf/__init__.py b/django/conf/__init__.py index 628b1f7e4d..f8018f723b 100644 --- a/django/conf/__init__.py +++ b/django/conf/__init__.py @@ -9,9 +9,11 @@ for a list of all possible variables. import importlib import os import time +import traceback import warnings from pathlib import Path +import django from django.conf import global_settings from django.core.exceptions import ImproperlyConfigured from django.utils.deprecation import RemovedInDjango50Warning @@ -19,6 +21,12 @@ from django.utils.functional import LazyObject, empty ENVIRONMENT_VARIABLE = "DJANGO_SETTINGS_MODULE" +USE_L10N_DEPRECATED_MSG = ( + 'The USE_L10N setting is deprecated. Starting with Django 5.0, localized ' + 'formatting of data will always be enabled. For example Django will ' + 'display numbers and dates using the format of the current locale.' +) + class SettingsReference(str): """ @@ -129,6 +137,27 @@ class LazySettings(LazyObject): """Return True if the settings have already been configured.""" return self._wrapped is not empty + @property + def USE_L10N(self): + stack = traceback.extract_stack() + # Show a warning if the setting is used outside of Django. + # Stack index: -1 this line, -2 the caller. + filename, _, _, _ = stack[-2] + if not filename.startswith(os.path.dirname(django.__file__)): + warnings.warn( + USE_L10N_DEPRECATED_MSG, + RemovedInDjango50Warning, + stacklevel=2, + ) + return self.__getattr__('USE_L10N') + + # RemovedInDjango50Warning. + @property + def _USE_L10N_INTERNAL(self): + # Special hook to avoid checking a traceback in internal use on hot + # paths. + return self.__getattr__('USE_L10N') + class Settings: def __init__(self, settings_module): @@ -179,6 +208,9 @@ class Settings: os.environ['TZ'] = self.TIME_ZONE time.tzset() + if self.is_overridden('USE_L10N'): + warnings.warn(USE_L10N_DEPRECATED_MSG, RemovedInDjango50Warning) + def is_overridden(self, setting): return setting in self._explicit_settings @@ -210,6 +242,8 @@ class UserSettingsHolder: def __setattr__(self, name, value): self._deleted.discard(name) + if name == 'USE_L10N': + warnings.warn(USE_L10N_DEPRECATED_MSG, RemovedInDjango50Warning) super().__setattr__(name, value) def __delattr__(self, name): diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py index b9541d81b5..ab69316314 100644 --- a/django/conf/global_settings.py +++ b/django/conf/global_settings.py @@ -167,7 +167,7 @@ LANGUAGE_COOKIE_SAMESITE = None # If you set this to True, Django will format dates, numbers and calendars # according to user current locale. -USE_L10N = False +USE_L10N = True # Not-necessarily-technical managers of the site. They get broken link # notifications and other various emails. diff --git a/django/conf/locale/en/formats.py b/django/conf/locale/en/formats.py index ccace3d2b3..f5af6509c6 100644 --- a/django/conf/locale/en/formats.py +++ b/django/conf/locale/en/formats.py @@ -2,24 +2,36 @@ # # The *_FORMAT strings use the Django date format syntax, # see https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date -DATE_FORMAT = 'N j, Y' -TIME_FORMAT = 'P' -DATETIME_FORMAT = 'N j, Y, P' -YEAR_MONTH_FORMAT = 'F Y' -MONTH_DAY_FORMAT = 'F j' -SHORT_DATE_FORMAT = 'm/d/Y' -SHORT_DATETIME_FORMAT = 'm/d/Y P' -FIRST_DAY_OF_WEEK = 0 # Sunday +# Formatting for date objects. +DATE_FORMAT = 'N j, Y' +# Formatting for time objects. +TIME_FORMAT = 'P' +# Formatting for datetime objects. +DATETIME_FORMAT = 'N j, Y, P' +# Formatting for date objects when only the year and month are relevant. +YEAR_MONTH_FORMAT = 'F Y' +# Formatting for date objects when only the month and day are relevant. +MONTH_DAY_FORMAT = 'F j' +# Short formatting for date objects. +SHORT_DATE_FORMAT = 'm/d/Y' +# Short formatting for datetime objects. +SHORT_DATETIME_FORMAT = 'm/d/Y P' +# First day of week, to be used on calendars. +# 0 means Sunday, 1 means Monday... +FIRST_DAY_OF_WEEK = 0 + +# Formats to be used when parsing dates from input boxes, in order. # The *_INPUT_FORMATS strings use the Python strftime format syntax, # see https://docs.python.org/library/datetime.html#strftime-strptime-behavior +# Note that these format strings are different from the ones to display dates. # Kept ISO formats as they are in first position DATE_INPUT_FORMATS = [ '%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', # '2006-10-25', '10/25/2006', '10/25/06' - # '%b %d %Y', '%b %d, %Y', # 'Oct 25 2006', 'Oct 25, 2006' - # '%d %b %Y', '%d %b, %Y', # '25 Oct 2006', '25 Oct, 2006' - # '%B %d %Y', '%B %d, %Y', # 'October 25 2006', 'October 25, 2006' - # '%d %B %Y', '%d %B, %Y', # '25 October 2006', '25 October, 2006' + '%b %d %Y', '%b %d, %Y', # 'Oct 25 2006', 'Oct 25, 2006' + '%d %b %Y', '%d %b, %Y', # '25 Oct 2006', '25 Oct, 2006' + '%B %d %Y', '%B %d, %Y', # 'October 25 2006', 'October 25, 2006' + '%d %B %Y', '%d %B, %Y', # '25 October 2006', '25 October, 2006' ] DATETIME_INPUT_FORMATS = [ '%Y-%m-%d %H:%M:%S', # '2006-10-25 14:30:59' @@ -32,6 +44,16 @@ DATETIME_INPUT_FORMATS = [ '%m/%d/%y %H:%M:%S.%f', # '10/25/06 14:30:59.000200' '%m/%d/%y %H:%M', # '10/25/06 14:30' ] +TIME_INPUT_FORMATS = [ + '%H:%M:%S', # '14:30:59' + '%H:%M:%S.%f', # '14:30:59.000200' + '%H:%M', # '14:30' +] + +# Decimal separator symbol. DECIMAL_SEPARATOR = '.' +# Thousand separator symbol. THOUSAND_SEPARATOR = ',' +# Number of digits that will be together, when splitting them by +# THOUSAND_SEPARATOR. 0 means no grouping, 3 means splitting by thousands. NUMBER_GROUPING = 3 diff --git a/django/conf/project_template/project_name/settings.py-tpl b/django/conf/project_template/project_name/settings.py-tpl index e949752df4..3b6caab333 100644 --- a/django/conf/project_template/project_name/settings.py-tpl +++ b/django/conf/project_template/project_name/settings.py-tpl @@ -109,8 +109,6 @@ TIME_ZONE = 'UTC' USE_I18N = True -USE_L10N = True - USE_TZ = True diff --git a/django/utils/formats.py b/django/utils/formats.py index cffbb34398..781d334a8e 100644 --- a/django/utils/formats.py +++ b/django/utils/formats.py @@ -104,7 +104,11 @@ def get_format(format_type, lang=None, use_l10n=None): If use_l10n is provided and is not None, it forces the value to be localized (or not), overriding the value of settings.USE_L10N. """ - use_l10n = use_l10n or (use_l10n is None and settings.USE_L10N) + use_l10n = use_l10n or (use_l10n is None and ( + settings._USE_L10N_INTERNAL + if hasattr(settings, '_USE_L10N_INTERNAL') + else settings.USE_L10N + )) if use_l10n and lang is None: lang = get_language() cache_key = (format_type, lang) @@ -168,7 +172,11 @@ def number_format(value, decimal_pos=None, use_l10n=None, force_grouping=False): If use_l10n is provided and is not None, it forces the value to be localized (or not), overriding the value of settings.USE_L10N. """ - use_l10n = use_l10n or (use_l10n is None and settings.USE_L10N) + use_l10n = use_l10n or (use_l10n is None and ( + settings._USE_L10N_INTERNAL + if hasattr(settings, '_USE_L10N_INTERNAL') + else settings.USE_L10N + )) lang = get_language() if use_l10n else None return numberformat.format( value, diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt index 77642cffd1..6154fefa3b 100644 --- a/docs/internals/deprecation.txt +++ b/docs/internals/deprecation.txt @@ -34,6 +34,8 @@ details on these changes. ``StringAgg`` aggregates will return ``None`` when there are no rows instead of ``[]``, ``[]``, and ``''`` respectively. +* The ``USE_L10N`` setting will be removed. + .. _deprecation-removed-in-4.1: 4.1 diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt index cc58192bd4..12d89142d1 100644 --- a/docs/ref/settings.txt +++ b/docs/ref/settings.txt @@ -2774,7 +2774,7 @@ See also :setting:`LANGUAGE_CODE`, :setting:`USE_L10N` and :setting:`USE_TZ`. ``USE_L10N`` ------------ -Default: ``False`` +Default: ``True`` A boolean that specifies if localized formatting of data will be enabled by default or not. If this is set to ``True``, e.g. Django will display numbers and @@ -2782,10 +2782,15 @@ dates using the format of the current locale. See also :setting:`LANGUAGE_CODE`, :setting:`USE_I18N` and :setting:`USE_TZ`. -.. note:: +.. versionchanged:: 4.0 - The default :file:`settings.py` file created by :djadmin:`django-admin - startproject ` includes ``USE_L10N = True`` for convenience. + In older versions, the default value is ``False``. + +.. deprecated:: 4.0 + + This setting is deprecated. Starting with Django 5.0, localized formatting + of data will always be enabled. For example Django will display numbers and + dates using the format of the current locale. .. setting:: USE_THOUSAND_SEPARATOR diff --git a/docs/releases/1.10.txt b/docs/releases/1.10.txt index d2f804b8c1..8b0303352a 100644 --- a/docs/releases/1.10.txt +++ b/docs/releases/1.10.txt @@ -918,7 +918,7 @@ Miscellaneous To adapt, move the fragment outside the template tag: ``{% static 'img.svg' %}#fragment``. -* When :setting:`USE_L10N` is ``True``, localization is now applied for the +* When ``USE_L10N`` is ``True``, localization is now applied for the :tfilter:`date` and :tfilter:`time` filters when no format string is specified. The ``DATE_FORMAT`` and ``TIME_FORMAT`` specifiers from the active locale are used instead of the settings of the same name. diff --git a/docs/releases/1.2.txt b/docs/releases/1.2.txt index 30e39ac1be..5d7d6cc836 100644 --- a/docs/releases/1.2.txt +++ b/docs/releases/1.2.txt @@ -936,7 +936,7 @@ Date format helper functions ``django.utils.translation.get_date_formats()`` and ``django.utils.translation.get_partial_date_formats()`` have been deprecated in favor of the appropriate calls to ``django.utils.formats.get_format()``, -which is locale-aware when :setting:`USE_L10N` is set to ``True``, and falls +which is locale-aware when ``USE_L10N`` is set to ``True``, and falls back to default settings if set to ``False``. To get the different date formats, instead of writing this:: diff --git a/docs/releases/2.0.txt b/docs/releases/2.0.txt index 7ad0a27ed4..c3730a794b 100644 --- a/docs/releases/2.0.txt +++ b/docs/releases/2.0.txt @@ -558,7 +558,7 @@ Miscellaneous * :class:`~django.views.generic.base.RedirectView` no longer silences ``NoReverseMatch`` if the ``pattern_name`` doesn't exist. -* When :setting:`USE_L10N` is off, :class:`~django.forms.FloatField` and +* When ``USE_L10N`` is off, :class:`~django.forms.FloatField` and :class:`~django.forms.DecimalField` now respect :setting:`DECIMAL_SEPARATOR` and :setting:`THOUSAND_SEPARATOR` during validation. For example, with the settings:: diff --git a/docs/releases/3.2.txt b/docs/releases/3.2.txt index 828add0fea..76d1ade6d5 100644 --- a/docs/releases/3.2.txt +++ b/docs/releases/3.2.txt @@ -672,7 +672,7 @@ Miscellaneous and underscores. * The :tfilter:`intcomma` and :tfilter:`intword` template filters no longer - depend on the :setting:`USE_L10N` setting. + depend on the ``USE_L10N`` setting. * Support for ``argon2-cffi`` < 19.1.0 is removed. diff --git a/docs/releases/4.0.txt b/docs/releases/4.0.txt index 8f910ad9db..709363a08f 100644 --- a/docs/releases/4.0.txt +++ b/docs/releases/4.0.txt @@ -579,8 +579,11 @@ Miscellaneous Django 3.2. * The :tfilter:`floatformat` template filter no longer depends on the - :setting:`USE_L10N` setting and always returns localized output. Use the - ``u`` suffix to disable localization. + ``USE_L10N`` setting and always returns localized output. Use the ``u`` + suffix to disable localization. + +* The default value of the ``USE_L10N`` setting is changed to ``True``. See the + :ref:`Localization section ` above for more details. .. _deprecated-features-4.0: @@ -601,6 +604,20 @@ Note that the default :file:`settings.py` file created by You can set ``USE_TZ`` to ``False`` in your project settings before then to opt-out. +.. _use_l10n_deprecation: + +Localization +------------ + +In order to follow good practice, the default value of the ``USE_L10N`` setting +is changed from ``False`` to ``True``. + +Moreover ``USE_L10N`` is deprecated as of this release. Starting with Django +5.0, by default, any date or number displayed by Django will be localized. + +The :ttag:`{% localize %} ` tag and the :tfilter:`localize`/ +:tfilter:`unlocalize` filters will still be honored by Django. + Miscellaneous ------------- diff --git a/docs/topics/i18n/formatting.txt b/docs/topics/i18n/formatting.txt index 16fd7ca0cb..671901dcdc 100644 --- a/docs/topics/i18n/formatting.txt +++ b/docs/topics/i18n/formatting.txt @@ -18,18 +18,16 @@ necessary to set :setting:`USE_L10N = True ` in your settings file. .. note:: - The default :file:`settings.py` file created by :djadmin:`django-admin - startproject ` includes :setting:`USE_L10N = True ` - for convenience. Note, however, that to enable number formatting with - thousand separators it is necessary to set :setting:`USE_THOUSAND_SEPARATOR - = True ` in your settings file. Alternatively, you - could use :tfilter:`intcomma` to format numbers in your template. + To enable number formatting with thousand separators, it is necessary to + set :setting:`USE_THOUSAND_SEPARATOR = True ` in + your settings file. Alternatively, you could use :tfilter:`intcomma` to + format numbers in your template. .. note:: - There is also an independent but related :setting:`USE_I18N` setting that - controls if Django should activate translation. See - :doc:`/topics/i18n/translation` for more details. + There is a related :setting:`USE_I18N` setting that controls if Django + should activate translation. See :doc:`/topics/i18n/translation` for more + details. Locale aware input in forms =========================== diff --git a/docs/topics/i18n/timezones.txt b/docs/topics/i18n/timezones.txt index 847e5ff593..5b475bd44f 100644 --- a/docs/topics/i18n/timezones.txt +++ b/docs/topics/i18n/timezones.txt @@ -47,12 +47,6 @@ functions in :mod:`django.utils.timezone`. startproject ` includes :setting:`USE_TZ = True ` for convenience. -.. note:: - - There is also an independent but related :setting:`USE_L10N` setting that - controls whether Django should activate format localization. See - :doc:`/topics/i18n/formatting` for more details. - If you're wrestling with a particular problem, start with the :ref:`time zone FAQ `. diff --git a/docs/topics/i18n/translation.txt b/docs/topics/i18n/translation.txt index 4c5b8181bc..99fc41ebb6 100644 --- a/docs/topics/i18n/translation.txt +++ b/docs/topics/i18n/translation.txt @@ -29,12 +29,6 @@ use internationalization, you should take the two seconds to set :setting:`USE_I18N = False ` in your settings file. Then Django will make some optimizations so as not to load the internationalization machinery. -.. note:: - - There is also an independent but related :setting:`USE_L10N` setting that - controls if Django should implement format localization. See - :doc:`/topics/i18n/formatting` for more details. - .. note:: Make sure you've activated translation for your project (the fastest way is diff --git a/tests/admin_inlines/tests.py b/tests/admin_inlines/tests.py index 12f36f4483..c50ad8cf1d 100644 --- a/tests/admin_inlines/tests.py +++ b/tests/admin_inlines/tests.py @@ -382,7 +382,7 @@ class TestInline(TestDataMixin, TestCase): html=True ) - @override_settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True) + @override_settings(USE_THOUSAND_SEPARATOR=True) def test_localize_pk_shortcut(self): """ The "View on Site" link is correct for locales that use thousand diff --git a/tests/admin_utils/test_logentry.py b/tests/admin_utils/test_logentry.py index ca7c7a4c41..8d8f4ef9ee 100644 --- a/tests/admin_utils/test_logentry.py +++ b/tests/admin_utils/test_logentry.py @@ -74,7 +74,6 @@ class LogEntryTests(TestCase): logentry = LogEntry(change_message='non-JSON string') self.assertEqual(logentry.get_change_message(), logentry.change_message) - @override_settings(USE_L10N=True) def test_logentry_change_message_localized_datetime_input(self): """ Localized date/time inputs shouldn't affect changed form data detection. diff --git a/tests/admin_utils/tests.py b/tests/admin_utils/tests.py index 5960759a4d..77db318693 100644 --- a/tests/admin_utils/tests.py +++ b/tests/admin_utils/tests.py @@ -201,7 +201,7 @@ class UtilsTests(SimpleTestCase): display_value = display_for_field(12345, models.IntegerField(), self.empty_value) self.assertEqual(display_value, '12345') - @override_settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True) + @override_settings(USE_THOUSAND_SEPARATOR=True) def test_number_formats_with_thousand_separator_display_for_field(self): display_value = display_for_field(12345.6789, models.FloatField(), self.empty_value) self.assertEqual(display_value, '12,345.6789') @@ -219,7 +219,7 @@ class UtilsTests(SimpleTestCase): display_value = display_for_value([1, 2, 'buckle', 'my', 'shoe'], self.empty_value) self.assertEqual(display_value, '1, 2, buckle, my, shoe') - @override_settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True) + @override_settings(USE_THOUSAND_SEPARATOR=True) def test_list_display_for_value_boolean(self): self.assertEqual( display_for_value(True, '', boolean=True), diff --git a/tests/admin_views/test_actions.py b/tests/admin_views/test_actions.py index 445e437fc2..6c5aa5ad53 100644 --- a/tests/admin_views/test_actions.py +++ b/tests/admin_views/test_actions.py @@ -72,7 +72,7 @@ class AdminActionsTest(TestCase): self.assertContains(response, 'Are you sure you want to delete the selected subscribers?') self.assertContains(response, '
    ', html=True) - @override_settings(USE_THOUSAND_SEPARATOR=True, USE_L10N=True, NUMBER_GROUPING=3) + @override_settings(USE_THOUSAND_SEPARATOR=True, NUMBER_GROUPING=3) def test_non_localized_pk(self): """ If USE_THOUSAND_SEPARATOR is set, the ids for the objects selected for diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index b277476296..a8524379f8 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -109,7 +109,7 @@ class AdminFieldExtractionMixin: return field -@override_settings(ROOT_URLCONF='admin_views.urls', USE_I18N=True, USE_L10N=False, LANGUAGE_CODE='en') +@override_settings(ROOT_URLCONF='admin_views.urls', USE_I18N=True, LANGUAGE_CODE='en') class AdminViewBasicTestCase(TestCase): @classmethod @@ -802,12 +802,12 @@ class AdminViewBasicTest(AdminViewBasicTestCase): response = self.client.get(reverse('admin-extra-context:jsi18n')) self.assertEqual(response.status_code, 200) - def test_L10N_deactivated(self): + def test_jsi18n_format_fallback(self): """ - Check if L10N is deactivated, the JavaScript i18n view doesn't - return localized date/time formats. Refs #14824. + The JavaScript i18n view doesn't return localized date/time formats + when the selected language cannot be found. """ - with self.settings(LANGUAGE_CODE='ru', USE_L10N=False), translation.override('none'): + with self.settings(LANGUAGE_CODE='ru'), translation.override('none'): response = self.client.get(reverse('admin:jsi18n')) self.assertNotContains(response, '%d.%m.%Y %H:%M:%S') self.assertContains(response, '%Y-%m-%d %H:%M:%S') @@ -4541,7 +4541,7 @@ class PrePopulatedTest(TestCase): ""id": "#id_prepopulatedsubpost_set-0-subslug"" ) - @override_settings(USE_THOUSAND_SEPARATOR=True, USE_L10N=True) + @override_settings(USE_THOUSAND_SEPARATOR=True) def test_prepopulated_maxlength_localized(self): """ Regression test for #15938: if USE_THOUSAND_SEPARATOR is set, make sure @@ -5704,7 +5704,7 @@ class ValidXHTMLTests(TestCase): self.assertNotContains(response, ' xml:lang=""') -@override_settings(ROOT_URLCONF='admin_views.urls', USE_THOUSAND_SEPARATOR=True, USE_L10N=True) +@override_settings(ROOT_URLCONF='admin_views.urls', USE_THOUSAND_SEPARATOR=True) class DateHierarchyTests(TestCase): @classmethod diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py index 1896279ec7..1bb4c9a9b1 100644 --- a/tests/admin_widgets/tests.py +++ b/tests/admin_widgets/tests.py @@ -338,7 +338,7 @@ class AdminSplitDateTimeWidgetTest(SimpleTestCase): def test_localization(self): w = widgets.AdminSplitDateTime() - with self.settings(USE_L10N=True), translation.override('de-at'): + with translation.override('de-at'): w.is_localized = True self.assertHTMLEqual( w.render('test', datetime(2007, 12, 1, 9, 30)), @@ -939,7 +939,7 @@ class DateTimePickerSeleniumTests(AdminWidgetSeleniumTestCase): expected_caption = '{:s} {:d}'.format(may_translation.upper(), 1984) # Test with every locale - with override_settings(LANGUAGE_CODE=language_code, USE_L10N=True): + with override_settings(LANGUAGE_CODE=language_code): # Open a page that has a date picker widget url = reverse('admin:admin_widgets_member_change', args=(member.pk,)) diff --git a/tests/deprecation/test_use_l10n.py b/tests/deprecation/test_use_l10n.py new file mode 100644 index 0000000000..0744e34ea0 --- /dev/null +++ b/tests/deprecation/test_use_l10n.py @@ -0,0 +1,43 @@ +import sys +from types import ModuleType + +from django.conf import USE_L10N_DEPRECATED_MSG, Settings, settings +from django.test import TestCase, ignore_warnings +from django.utils.deprecation import RemovedInDjango50Warning + + +class DeprecationTests(TestCase): + msg = USE_L10N_DEPRECATED_MSG + + def test_override_settings_warning(self): + # Warning is raised when USE_L10N is set in UserSettingsHolder (used by + # the @override_settings decorator). + with self.assertRaisesMessage(RemovedInDjango50Warning, self.msg): + with self.settings(USE_L10N=True): + pass + + def test_settings_init_warning(self): + settings_module = ModuleType('fake_settings_module') + settings_module.SECRET_KEY = 'foo' + settings_module.USE_TZ = True + settings_module.USE_L10N = False + sys.modules['fake_settings_module'] = settings_module + try: + with self.assertRaisesMessage(RemovedInDjango50Warning, self.msg): + Settings('fake_settings_module') + finally: + del sys.modules['fake_settings_module'] + + def test_access_warning(self): + with self.assertRaisesMessage(RemovedInDjango50Warning, self.msg): + settings.USE_L10N + # Works a second time. + with self.assertRaisesMessage(RemovedInDjango50Warning, self.msg): + settings.USE_L10N + + @ignore_warnings(category=RemovedInDjango50Warning) + def test_access(self): + with self.settings(USE_L10N=False): + self.assertIs(settings.USE_L10N, False) + # Works a second time. + self.assertIs(settings.USE_L10N, False) diff --git a/tests/forms_tests/field_tests/test_datefield.py b/tests/forms_tests/field_tests/test_datefield.py index c0e369cd0c..10d77bf1bb 100644 --- a/tests/forms_tests/field_tests/test_datefield.py +++ b/tests/forms_tests/field_tests/test_datefield.py @@ -2,7 +2,7 @@ from datetime import date, datetime from django.core.exceptions import ValidationError from django.forms import DateField, Form, HiddenInput, SelectDateWidget -from django.test import SimpleTestCase, override_settings +from django.test import SimpleTestCase from django.utils import translation @@ -37,7 +37,6 @@ class DateFieldTest(SimpleTestCase): d = GetDate({'mydate_month': '1', 'mydate_day': '1', 'mydate_year': '2010'}) self.assertIn('