summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2022-05-28 11:52:06 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-05-31 06:09:39 +0200
commit292f372768836e2aebc713064c5139e8067eebcb (patch)
tree2f95fd95d27e18bc35f2d9378172cca97ee1935c
parent8c0886b068ba4e224dd78104b93c9638b860b398 (diff)
Fixed #33748 -- Fixed date template filter crash with lazy format.
Regression in 659d2421c7adbbcd205604002d521d82d6b0b465.
-rw-r--r--django/utils/formats.py1
-rw-r--r--tests/i18n/tests.py3
-rw-r--r--tests/template_tests/filter_tests/test_date.py5
3 files changed, 9 insertions, 0 deletions
diff --git a/django/utils/formats.py b/django/utils/formats.py
index 3f38322d84..b0a66e4e25 100644
--- a/django/utils/formats.py
+++ b/django/utils/formats.py
@@ -113,6 +113,7 @@ def get_format(format_type, lang=None, use_l10n=None):
use_l10n = settings.USE_L10N
if use_l10n and lang is None:
lang = get_language()
+ format_type = str(format_type) # format_type may be lazy.
cache_key = (format_type, lang)
try:
return _format_cache[cache_key]
diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py
index 0093181f64..d79cdcd34d 100644
--- a/tests/i18n/tests.py
+++ b/tests/i18n/tests.py
@@ -1518,6 +1518,9 @@ class FormattingTests(SimpleTestCase):
with translation.override("de", deactivate=True):
self.assertEqual(".", get_format("DECIMAL_SEPARATOR", lang="en"))
+ def test_get_format_lazy_format(self):
+ self.assertEqual(get_format(gettext_lazy("DATE_FORMAT")), "N j, Y")
+
def test_localize_templatetag_and_filter(self):
"""
Test the {% localize %} templatetag and the localize/unlocalize filters.
diff --git a/tests/template_tests/filter_tests/test_date.py b/tests/template_tests/filter_tests/test_date.py
index a7c694d50e..b998f83ba6 100644
--- a/tests/template_tests/filter_tests/test_date.py
+++ b/tests/template_tests/filter_tests/test_date.py
@@ -72,6 +72,11 @@ class DateTests(TimezoneTestCase):
output = self.engine.render_to_string("date09", {"t": time(0, 0)})
self.assertEqual(output, "00:00")
+ @setup({"datelazy": '{{ t|date:_("H:i") }}'})
+ def test_date_lazy(self):
+ output = self.engine.render_to_string("datelazy", {"t": time(0, 0)})
+ self.assertEqual(output, "00:00")
+
class FunctionTests(SimpleTestCase):
def test_date(self):