From 2274a44572b6b3d8a19bd4a1d4c893ab2b0d51ca Mon Sep 17 00:00:00 2001 From: Sage Abdullah Date: Fri, 15 Dec 2023 11:54:01 +0000 Subject: [PATCH] Add default template for Button component --- .../templates/wagtailadmin/shared/button.html | 7 +++++++ wagtail/admin/widgets/button.py | 14 +++----------- 2 files changed, 10 insertions(+), 11 deletions(-) create mode 100644 wagtail/admin/templates/wagtailadmin/shared/button.html diff --git a/wagtail/admin/templates/wagtailadmin/shared/button.html b/wagtail/admin/templates/wagtailadmin/shared/button.html new file mode 100644 index 000000000000..d5cc29af7e28 --- /dev/null +++ b/wagtail/admin/templates/wagtailadmin/shared/button.html @@ -0,0 +1,7 @@ +{% load wagtailadmin_tags %} + + {% if button.icon_name %} + {% icon name=button.icon_name %} + {% endif %} + {{ button.label }} + diff --git a/wagtail/admin/widgets/button.py b/wagtail/admin/widgets/button.py index 1e8fe4836463..6d04277f4085 100644 --- a/wagtail/admin/widgets/button.py +++ b/wagtail/admin/widgets/button.py @@ -3,7 +3,6 @@ from django.forms.utils import flatatt from django.urls import reverse from django.utils.functional import cached_property -from django.utils.html import format_html from django.utils.http import urlencode from wagtail import hooks @@ -13,6 +12,7 @@ class Button(Component): + template_name = "wagtailadmin/shared/button.html" show = True label = "" icon_name = None @@ -43,16 +43,8 @@ def __init__( self.attrs["aria-label"] = self.attrs.pop("title") self.priority = priority - def render_html(self, parent_context=None): - if hasattr(self, "template_name"): - return super().render_html(parent_context) - else: - attrs = { - "href": self.url, - "class": self.classname, - } - attrs.update(self.attrs) - return format_html("{}", flatatt(attrs), self.label) + def get_context_data(self, parent_context): + return {"button": self} @property def base_attrs_string(self):