[4.1.x] Fixed #33748 -- Fixed date template filter crash with lazy format.
Regression in659d2421c7
. Backport of292f372768
from main
This commit is contained in:
parent
0210dbcbe3
commit
000e8e0d38
|
@ -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]
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue