Added handling for lazily evaluated page_description, fixes #8523 (#8527)

pull/8549/head
Stefan Hammer 2022-05-12 11:00:24 +02:00 zatwierdzone przez Matt Westcott
rodzic 9b659cb187
commit 5f38ddd8f7
4 zmienionych plików z 7 dodań i 1 usunięć

Wyświetl plik

@ -38,7 +38,7 @@ Changelog
* Split up linting / formatting tasks in Makefile into client and server components (Hitansh Shah)
* Add support for embedding Instagram reels (Luis Nell)
* Use Djangos JavaScript catalog feature to manage translatable strings in JavaScript (Karl Hobley)
* Add a `page_description` to the Page model, to provide help text for a given page type (Kalob Taulien, Thibaud Colas, Matt Westcott)
* Add a `page_description` to the Page model, to provide help text for a given page type (Kalob Taulien, Thibaud Colas, Matt Westcott, Stefan Hammer)
* Add `trimmed` attribute to all blocktrans tags, so spacing is more reliable in translated strings (Harris Lapiroff)
* Add documentation that describes how to use `ModelAdmin` to manage `Tag`s (Abdulmajeed Isa)
* Rename the setting `BASE_URL` (undocumented) to `WAGTAILADMIN_BASE_URL` and add to documentation, `BASE_URL` will be removed in a future release (Sandil Ranasinghe)

Wyświetl plik

@ -69,6 +69,7 @@ class TestPageCreation(TestCase, WagtailTestUtils):
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Business child")
self.assertContains(response, "A lazy business child page description")
# List should not contain page types not in the subpage_types list
self.assertNotContains(response, "Simple page")

Wyświetl plik

@ -1509,6 +1509,9 @@ class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase):
# make sure that page_description is actually a string rather than a model field
if isinstance(description, str):
return description
elif getattr(description, "_delegate_text", None):
# description is a lazy object (e.g. the result of gettext_lazy())
return str(description)
else:
return ""

Wyświetl plik

@ -11,6 +11,7 @@ from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.db import models
from django.shortcuts import redirect
from django.template.response import TemplateResponse
from django.utils.functional import lazystr
from modelcluster.contrib.taggit import ClusterTaggableManager
from modelcluster.fields import ParentalKey, ParentalManyToManyField
from modelcluster.models import ClusterableModel
@ -976,6 +977,7 @@ class BusinessChild(Page):
subpage_types = []
parent_page_types = ["tests.BusinessIndex", BusinessSubIndex]
page_description = lazystr("A lazy business child page description")
class BusinessNowherePage(Page):