Refs #32873 -- Avoided looking up settings._USE_L10N_INTERNAL twice.

This commit is contained in:
Collin Anderson 2022-02-22 14:26:51 -05:00 committed by GitHub
parent 7c318a8bdd
commit 7fd2deb3e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 16 deletions

View File

@ -106,14 +106,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_INTERNAL
if hasattr(settings, "_USE_L10N_INTERNAL")
else settings.USE_L10N
)
)
if use_l10n is None:
try:
use_l10n = settings._USE_L10N_INTERNAL
except AttributeError:
use_l10n = settings.USE_L10N
if use_l10n and lang is None:
lang = get_language()
cache_key = (format_type, lang)
@ -181,14 +178,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_INTERNAL
if hasattr(settings, "_USE_L10N_INTERNAL")
else settings.USE_L10N
)
)
if use_l10n is None:
try:
use_l10n = settings._USE_L10N_INTERNAL
except AttributeError:
use_l10n = settings.USE_L10N
lang = get_language() if use_l10n else None
return numberformat.format(
value,