kopia lustrzana https://github.com/wagtail/wagtail
Bug: Enable template tag `richtext` to convert lazy text strings (#11901)
Fixes #11900pull/11907/head
rodzic
763c990490
commit
b266e54ba9
|
@ -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)
|
* 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)
|
* 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: 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
|
6.1 (xx.xx.xxxx) - IN DEVELOPMENT
|
||||||
|
|
|
@ -21,6 +21,7 @@ depth: 1
|
||||||
### Bug fixes
|
### Bug fixes
|
||||||
|
|
||||||
* Make `WAGTAILIMAGES_CHOOSER_PAGE_SIZE` setting functional again (Rohit Sharma)
|
* Make `WAGTAILIMAGES_CHOOSER_PAGE_SIZE` setting functional again (Rohit Sharma)
|
||||||
|
* Enable `richtext` template tag to convert lazy translation values (Benjamin Bach)
|
||||||
|
|
||||||
|
|
||||||
### Documentation
|
### Documentation
|
||||||
|
|
|
@ -3,6 +3,7 @@ from django.shortcuts import resolve_url
|
||||||
from django.template.defaulttags import token_kwargs
|
from django.template.defaulttags import token_kwargs
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.utils.encoding import force_str
|
from django.utils.encoding import force_str
|
||||||
|
from django.utils.functional import Promise
|
||||||
from django.utils.html import conditional_escape
|
from django.utils.html import conditional_escape
|
||||||
|
|
||||||
from wagtail import VERSION, __version__
|
from wagtail import VERSION, __version__
|
||||||
|
@ -120,6 +121,8 @@ def richtext(value):
|
||||||
elif value is None:
|
elif value is None:
|
||||||
html = ""
|
html = ""
|
||||||
else:
|
else:
|
||||||
|
if isinstance(value, Promise):
|
||||||
|
value = str(value)
|
||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
html = expand_db_html(value)
|
html = expand_db_html(value)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -9,6 +9,7 @@ from django.test import TestCase
|
||||||
from django.test.utils import override_settings
|
from django.test.utils import override_settings
|
||||||
from django.urls.exceptions import NoReverseMatch
|
from django.urls.exceptions import NoReverseMatch
|
||||||
from django.utils.safestring import SafeString
|
from django.utils.safestring import SafeString
|
||||||
|
from django.utils.translation import gettext_lazy
|
||||||
|
|
||||||
from wagtail.coreutils import (
|
from wagtail.coreutils import (
|
||||||
get_dummy_request,
|
get_dummy_request,
|
||||||
|
@ -536,6 +537,10 @@ class TestRichtextTag(TestCase):
|
||||||
self.assertEqual(result, "Hello world!")
|
self.assertEqual(result, "Hello world!")
|
||||||
self.assertIsInstance(result, SafeString)
|
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):
|
def test_call_with_none(self):
|
||||||
result = richtext(None)
|
result = richtext(None)
|
||||||
self.assertEqual(result, "")
|
self.assertEqual(result, "")
|
||||||
|
|
Ładowanie…
Reference in New Issue