From 6a0bd93e5b6544f65dc848b626a198853e58a2ae Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Tue, 18 Mar 2025 23:14:48 +0000 Subject: [PATCH] Add an empty_value_display property on Column for use when value is blank This surfaces an issue with SearchPromotion having a broken string representation when the query string is None, so fix that too --- wagtail/admin/ui/tables/__init__.py | 10 +++++++--- wagtail/contrib/search_promotions/models.py | 8 +------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/wagtail/admin/ui/tables/__init__.py b/wagtail/admin/ui/tables/__init__.py index 8c593711b3..b483f0f0b0 100644 --- a/wagtail/admin/ui/tables/__init__.py +++ b/wagtail/admin/ui/tables/__init__.py @@ -141,6 +141,7 @@ class Column(BaseColumn): """A column that displays a single field of data from the model""" cell_template_name = "wagtailadmin/tables/cell.html" + empty_value_display = "" def get_value(self, instance): """ @@ -163,7 +164,11 @@ class Column(BaseColumn): # on templates to be explicitly localized or unlocalized. For numeric table cells, we # unlocalize them by default; developers may subclass Column to obtain formatted numbers. value = unlocalize(value) - context["value"] = value + + if not str(value).strip(): + context["value"] = self.empty_value_display + else: + context["value"] = value return context @@ -185,6 +190,7 @@ class TitleColumn(Column): """A column where data is styled as a title and wrapped in a link or