Fixed #33748 -- Fixed date template filter crash with lazy format.
Regression in 659d2421c7
.
This commit is contained in:
parent
8c0886b068
commit
292f372768
|
@ -113,6 +113,7 @@ def get_format(format_type, lang=None, use_l10n=None):
|
||||||
use_l10n = settings.USE_L10N
|
use_l10n = settings.USE_L10N
|
||||||
if use_l10n and lang is None:
|
if use_l10n and lang is None:
|
||||||
lang = get_language()
|
lang = get_language()
|
||||||
|
format_type = str(format_type) # format_type may be lazy.
|
||||||
cache_key = (format_type, lang)
|
cache_key = (format_type, lang)
|
||||||
try:
|
try:
|
||||||
return _format_cache[cache_key]
|
return _format_cache[cache_key]
|
||||||
|
|
|
@ -1518,6 +1518,9 @@ class FormattingTests(SimpleTestCase):
|
||||||
with translation.override("de", deactivate=True):
|
with translation.override("de", deactivate=True):
|
||||||
self.assertEqual(".", get_format("DECIMAL_SEPARATOR", lang="en"))
|
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):
|
def test_localize_templatetag_and_filter(self):
|
||||||
"""
|
"""
|
||||||
Test the {% localize %} templatetag and the localize/unlocalize filters.
|
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)})
|
output = self.engine.render_to_string("date09", {"t": time(0, 0)})
|
||||||
self.assertEqual(output, "00:00")
|
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):
|
class FunctionTests(SimpleTestCase):
|
||||||
def test_date(self):
|
def test_date(self):
|
||||||
|
|
Loading…
Reference in New Issue