1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Refs #32873 -- Removed settings.USE_L10N per deprecation timeline.

This commit is contained in:
Mariusz Felisiak
2023-01-06 14:46:33 +01:00
parent 0be8095b25
commit 8d98f99a4a
19 changed files with 136 additions and 573 deletions

View File

@@ -30,12 +30,6 @@ USE_DEPRECATED_PYTZ_DEPRECATED_MSG = (
"code to use zoneinfo and remove the USE_DEPRECATED_PYTZ setting."
)
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."
)
CSRF_COOKIE_MASKED_DEPRECATED_MSG = (
"The CSRF_COOKIE_MASKED transitional setting is deprecated. Support for "
"it will be removed in Django 5.0."
@@ -173,20 +167,6 @@ class LazySettings(LazyObject):
if not filename.startswith(os.path.dirname(django.__file__)):
warnings.warn(message, category, stacklevel=2)
@property
def USE_L10N(self):
self._show_deprecation_warning(
USE_L10N_DEPRECATED_MSG, RemovedInDjango50Warning
)
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")
# RemovedInDjango51Warning.
@property
def DEFAULT_FILE_STORAGE(self):
@@ -255,9 +235,6 @@ class Settings:
os.environ["TZ"] = self.TIME_ZONE
time.tzset()
if self.is_overridden("USE_L10N"):
warnings.warn(USE_L10N_DEPRECATED_MSG, RemovedInDjango50Warning)
if self.is_overridden("DEFAULT_FILE_STORAGE"):
if self.is_overridden("STORAGES"):
raise ImproperlyConfigured(
@@ -304,8 +281,6 @@ class UserSettingsHolder:
def __setattr__(self, name, value):
self._deleted.discard(name)
if name == "USE_L10N":
warnings.warn(USE_L10N_DEPRECATED_MSG, RemovedInDjango50Warning)
if name == "CSRF_COOKIE_MASKED":
warnings.warn(CSRF_COOKIE_MASKED_DEPRECATED_MSG, RemovedInDjango50Warning)
if name == "DEFAULT_FILE_STORAGE":

View File

@@ -171,11 +171,6 @@ LANGUAGE_COOKIE_SECURE = False
LANGUAGE_COOKIE_HTTPONLY = False
LANGUAGE_COOKIE_SAMESITE = None
# If you set this to True, Django will format dates, numbers and calendars
# according to user current locale.
USE_L10N = True
# Not-necessarily-technical managers of the site. They get broken link
# notifications and other various emails.
MANAGERS = ADMINS

View File

@@ -7,8 +7,7 @@ register = Library()
@register.filter(is_safe=False)
def localize(value):
"""
Force a value to be rendered as a localized value,
regardless of the value of ``settings.USE_L10N``.
Force a value to be rendered as a localized value.
"""
return str(formats.localize(value, use_l10n=True))
@@ -16,8 +15,7 @@ def localize(value):
@register.filter(is_safe=False)
def unlocalize(value):
"""
Force a value to be rendered as a non-localized value,
regardless of the value of ``settings.USE_L10N``.
Force a value to be rendered as a non-localized value.
"""
return str(formats.localize(value, use_l10n=False))
@@ -41,8 +39,7 @@ class LocalizeNode(Node):
@register.tag("localize")
def localize_tag(parser, token):
"""
Force or prevents localization of values, regardless of the value of
`settings.USE_L10N`.
Force or prevents localization of values.
Sample usage::

View File

@@ -104,13 +104,10 @@ def get_format(format_type, lang=None, use_l10n=None):
format_type is the name of the format, e.g. 'DATE_FORMAT'.
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.
be localized (or not), otherwise it's always localized.
"""
if use_l10n is None:
try:
use_l10n = settings._USE_L10N_INTERNAL
except AttributeError:
use_l10n = settings.USE_L10N
use_l10n = True
if use_l10n and lang is None:
lang = get_language()
format_type = str(format_type) # format_type may be lazy.
@@ -153,7 +150,7 @@ def date_format(value, format=None, use_l10n=None):
localizable format.
If use_l10n is provided and is not None, that will force the value to
be localized (or not), overriding the value of settings.USE_L10N.
be localized (or not), otherwise it's always localized.
"""
return dateformat.format(
value, get_format(format or "DATE_FORMAT", use_l10n=use_l10n)
@@ -165,7 +162,7 @@ def time_format(value, format=None, use_l10n=None):
Format a datetime.time object using a localizable format.
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.
be localized (or not), otherwise it's always localized.
"""
return dateformat.time_format(
value, get_format(format or "TIME_FORMAT", use_l10n=use_l10n)
@@ -177,13 +174,10 @@ def number_format(value, decimal_pos=None, use_l10n=None, force_grouping=False):
Format a numeric value using localization settings.
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.
be localized (or not), otherwise it's always localized.
"""
if use_l10n is None:
try:
use_l10n = settings._USE_L10N_INTERNAL
except AttributeError:
use_l10n = settings.USE_L10N
use_l10n = True
lang = get_language() if use_l10n else None
return numberformat.format(
value,
@@ -202,7 +196,7 @@ def localize(value, use_l10n=None):
formatted as a string using current locale format.
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.
be localized (or not), otherwise it's always localized.
"""
if isinstance(value, str): # Handle strings first for performance reasons.
return value

View File

@@ -27,9 +27,9 @@ def format(
"""
if number is None or number == "":
return mark_safe(number)
use_grouping = (
use_l10n or (use_l10n is None and settings.USE_L10N)
) and settings.USE_THOUSAND_SEPARATOR
if use_l10n is None:
use_l10n = True
use_grouping = use_l10n and settings.USE_THOUSAND_SEPARATOR
use_grouping = use_grouping or force_grouping
use_grouping = use_grouping and grouping != 0
# Make the common case fast