Move default block preview template definition to Block.DEFAULT_PREVIEW_TEMPLATE

pull/12700/head
Sage Abdullah 2025-01-15 12:25:27 +00:00
rodzic 3b8e15561d
commit 4c8ea0e54c
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: EB1A33CC51CC0217
2 zmienionych plików z 7 dodań i 9 usunięć

Wyświetl plik

@ -170,7 +170,6 @@ class PreviewRevision(View):
@method_decorator(xframe_options_sameorigin_override, name="get")
class StreamFieldBlockPreview(TemplateView):
template_name = "wagtailcore/shared/block_preview.html"
http_method_names = ("get",)
@cached_property
@ -207,12 +206,7 @@ class StreamFieldBlockPreview(TemplateView):
}
def get_template_names(self):
templates = [self.template_name]
if preview_template := self.block_def.get_preview_template(
self.block_value, self.base_context
):
templates.insert(0, preview_template)
return templates
return self.block_def.get_preview_template(self.block_value, self.base_context)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

Wyświetl plik

@ -59,6 +59,7 @@ class Block(metaclass=BaseBlock):
definition_registry = {}
TEMPLATE_VAR = "value"
DEFAULT_PREVIEW_TEMPLATE = "wagtailcore/shared/block_preview.html"
class Meta:
label = None
@ -287,7 +288,10 @@ class Block(metaclass=BaseBlock):
#
# Instead, the default preview template uses `{% include_block %}`,
# which will use `get_template` if a template is defined.
return getattr(self.meta, "preview_template", None)
return (
getattr(self.meta, "preview_template", None)
or self.DEFAULT_PREVIEW_TEMPLATE
)
def get_preview_value(self):
if hasattr(self.meta, "preview_value"):
@ -315,7 +319,7 @@ class Block(metaclass=BaseBlock):
or self.__class__.get_preview_value is not Block.get_preview_value
)
has_global_template = template_is_overridden(
"wagtailcore/shared/block_preview.html",
self.DEFAULT_PREVIEW_TEMPLATE,
"templates",
)
return has_specific_template or (has_preview_value and has_global_template)