Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
3188b49e
Kaydet (Commit)
3188b49e
authored
Ara 01, 2016
tarafından
Jaap Roes
Kaydeden (comit)
Claude Paroz
Ara 21, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #25753 -- Made get_format() cache the formats from Django settings
üst
1206d7fa
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
26 deletions
+34
-26
formats.py
django/utils/formats.py
+34
-26
No files found.
django/utils/formats.py
Dosyayı görüntüle @
3188b49e
...
...
@@ -112,32 +112,40 @@ def get_format(format_type, lang=None, use_l10n=None):
be localized (or not), overriding the value of settings.USE_L10N.
"""
format_type
=
force_str
(
format_type
)
if
use_l10n
or
(
use_l10n
is
None
and
settings
.
USE_L10N
):
if
lang
is
None
:
lang
=
get_language
()
cache_key
=
(
format_type
,
lang
)
try
:
cached
=
_format_cache
[
cache_key
]
if
cached
is
not
None
:
return
cached
except
KeyError
:
for
module
in
get_format_modules
(
lang
):
try
:
val
=
getattr
(
module
,
format_type
)
for
iso_input
in
ISO_INPUT_FORMATS
.
get
(
format_type
,
()):
if
iso_input
not
in
val
:
if
isinstance
(
val
,
tuple
):
val
=
list
(
val
)
val
.
append
(
iso_input
)
_format_cache
[
cache_key
]
=
val
return
val
except
AttributeError
:
pass
_format_cache
[
cache_key
]
=
None
if
format_type
not
in
FORMAT_SETTINGS
:
return
format_type
# Return the general setting by default
return
getattr
(
settings
,
format_type
)
use_l10n
=
use_l10n
or
(
use_l10n
is
None
and
settings
.
USE_L10N
)
if
use_l10n
and
lang
is
None
:
lang
=
get_language
()
cache_key
=
(
format_type
,
lang
)
try
:
return
_format_cache
[
cache_key
]
except
KeyError
:
pass
# The requested format_type has not been cached yet. Try to find it in any
# of the format_modules for the given lang if l10n is enabled. If it's not
# there or if l10n is disabled, fall back to the project settings.
val
=
None
if
use_l10n
:
for
module
in
get_format_modules
(
lang
):
try
:
val
=
getattr
(
module
,
format_type
)
if
val
is
not
None
:
break
except
AttributeError
:
pass
if
val
is
None
:
if
format_type
not
in
FORMAT_SETTINGS
:
return
format_type
val
=
getattr
(
settings
,
format_type
)
elif
format_type
in
ISO_INPUT_FORMATS
.
keys
():
# If a list of input formats from one of the format_modules was
# retrieved, make sure the ISO_INPUT_FORMATS are in this list.
val
=
list
(
val
)
for
iso_input
in
ISO_INPUT_FORMATS
.
get
(
format_type
,
()):
if
iso_input
not
in
val
:
val
.
append
(
iso_input
)
_format_cache
[
cache_key
]
=
val
return
val
get_format_lazy
=
lazy
(
get_format
,
six
.
text_type
,
list
,
tuple
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment