kopia lustrzana https://github.com/wagtail/wagtail
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 toopull/12964/head
rodzic
397edf2ec5
commit
6a0bd93e5b
|
@ -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 <label>"""
|
||||
|
||||
cell_template_name = "wagtailadmin/tables/title_cell.html"
|
||||
empty_value_display = gettext_lazy("(blank)")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -211,8 +217,6 @@ class TitleColumn(Column):
|
|||
|
||||
def get_cell_context_data(self, instance, parent_context):
|
||||
context = super().get_cell_context_data(instance, parent_context)
|
||||
if not str(context["value"]).strip():
|
||||
context["value"] = "(blank)"
|
||||
context["link_attrs"] = self.get_link_attrs(instance, parent_context)
|
||||
context["link_attrs"]["href"] = context["link_url"] = self.get_link_url(
|
||||
instance, parent_context
|
||||
|
|
|
@ -144,13 +144,7 @@ class SearchPromotion(models.Model):
|
|||
else:
|
||||
label = "external link"
|
||||
|
||||
return (
|
||||
'SearchPromotion(query="'
|
||||
+ self.query.query_string
|
||||
+ f'", {label}="'
|
||||
+ self.title
|
||||
+ '")'
|
||||
)
|
||||
return f'SearchPromotion(query="{self.query.query_string}", {label}="{self.title}")'
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.query.query_string} - {self.title}"
|
||||
|
|
Ładowanie…
Reference in New Issue