Bug: Enable template tag `richtext` to convert lazy text strings (#11901)

Fixes #11900
pull/11903/head
Benjamin Bach 2024-04-28 09:58:38 +02:00 zatwierdzone przez Matt Westcott
rodzic 763c990490
commit b266e54ba9
4 zmienionych plików z 10 dodań i 0 usunięć

Wyświetl plik

@ -8,6 +8,7 @@ Changelog
* Support a `HOSTNAMES` parameter on `WAGTAILFRONTENDCACHE` to define which hostnames a backend should respond to (Jake Howard, sponsored by Oxfam America)
* Refactor redirects edit view to use the generic `EditView` and breadcrumbs (Rohit Sharma)
* Fix: Make `WAGTAILIMAGES_CHOOSER_PAGE_SIZE` setting functional again (Rohit Sharma)
* Fix: Enable `richtext` template tag to convert lazy translation values (Benjamin Bach)
6.1 (xx.xx.xxxx) - IN DEVELOPMENT

Wyświetl plik

@ -21,6 +21,7 @@ depth: 1
### Bug fixes
* Make `WAGTAILIMAGES_CHOOSER_PAGE_SIZE` setting functional again (Rohit Sharma)
* Enable `richtext` template tag to convert lazy translation values (Benjamin Bach)
### Documentation

Wyświetl plik

@ -3,6 +3,7 @@ from django.shortcuts import resolve_url
from django.template.defaulttags import token_kwargs
from django.template.loader import render_to_string
from django.utils.encoding import force_str
from django.utils.functional import Promise
from django.utils.html import conditional_escape
from wagtail import VERSION, __version__
@ -120,6 +121,8 @@ def richtext(value):
elif value is None:
html = ""
else:
if isinstance(value, Promise):
value = str(value)
if isinstance(value, str):
html = expand_db_html(value)
else:

Wyświetl plik

@ -9,6 +9,7 @@ from django.test import TestCase
from django.test.utils import override_settings
from django.urls.exceptions import NoReverseMatch
from django.utils.safestring import SafeString
from django.utils.translation import gettext_lazy
from wagtail.coreutils import (
get_dummy_request,
@ -536,6 +537,10 @@ class TestRichtextTag(TestCase):
self.assertEqual(result, "Hello world!")
self.assertIsInstance(result, SafeString)
def test_call_with_lazy(self):
result = richtext(gettext_lazy("test"))
self.assertEqual(result, "test")
def test_call_with_none(self):
result = richtext(None)
self.assertEqual(result, "")