diff --git a/wagtail/admin/templates/wagtailadmin/pages/listing/_dropdown_items.html b/wagtail/admin/templates/wagtailadmin/pages/listing/_dropdown_items.html index 74bd45a489..332b37bbf2 100644 --- a/wagtail/admin/templates/wagtailadmin/pages/listing/_dropdown_items.html +++ b/wagtail/admin/templates/wagtailadmin/pages/listing/_dropdown_items.html @@ -1,7 +1,7 @@ {% load wagtailadmin_tags %} {% for button in buttons %} - + {% if button.icon_name %} {% icon name=button.icon_name %} {% endif %} diff --git a/wagtail/admin/templatetags/wagtailadmin_tags.py b/wagtail/admin/templatetags/wagtailadmin_tags.py index 8150c89f4f..18048ee1d9 100644 --- a/wagtail/admin/templatetags/wagtailadmin_tags.py +++ b/wagtail/admin/templatetags/wagtailadmin_tags.py @@ -515,7 +515,7 @@ def bulk_action_choices(context, app_label, model_name): + urlencode({"next": next_url}), attrs={"aria-label": action.aria_label}, priority=action.action_priority, - classes=action.classes | {"bulk-action-btn"}, + classname=" ".join(action.classes | {"bulk-action-btn"}), ) for action in bulk_actions_list ] @@ -524,7 +524,7 @@ def bulk_action_choices(context, app_label, model_name): more_button = ButtonWithDropdown( label=_("More"), attrs={"title": _("More bulk actions")}, - classes={"button", "button-secondary", "button-small"}, + classname="button button-secondary button-small", buttons=[ Button( label=action.display_name, @@ -536,7 +536,7 @@ def bulk_action_choices(context, app_label, model_name): + urlencode({"next": next_url}), attrs={"aria-label": action.aria_label}, priority=action.action_priority, - classes={"bulk-action-btn"}, + classname="bulk-action-btn", ) for action in bulk_action_more_list ], diff --git a/wagtail/admin/tests/test_buttons_hooks.py b/wagtail/admin/tests/test_buttons_hooks.py index 9fc534880b..1202f25fc0 100644 --- a/wagtail/admin/tests/test_buttons_hooks.py +++ b/wagtail/admin/tests/test_buttons_hooks.py @@ -307,16 +307,16 @@ class ButtonComparisonTestCase(SimpleTestCase): def setUp(self): self.button1 = Button( - "Label 1", "/url1", classes={"class1", "class2"}, priority=100 + "Label 1", "/url1", classname="class1 class2", priority=100 ) self.button2 = Button( - "Label 2", "/url2", classes={"class2", "class3"}, priority=200 + "Label 2", "/url2", classname="class2 class3", priority=200 ) self.button3 = Button( - "Label 1", "/url3", classes={"class1", "class2"}, priority=300 + "Label 1", "/url3", classname="class1 class2", priority=300 ) self.button4 = Button( - "Label 1", "/url1", classes={"class1", "class2"}, priority=100 + "Label 1", "/url1", classname="class1 class2", priority=100 ) def test_eq(self): diff --git a/wagtail/admin/widgets/button.py b/wagtail/admin/widgets/button.py index 760aacaec1..ce509c382f 100644 --- a/wagtail/admin/widgets/button.py +++ b/wagtail/admin/widgets/button.py @@ -10,11 +10,11 @@ class Button(Component): show = True def __init__( - self, label, url, classes=set(), icon_name=None, attrs={}, priority=1000 + self, label, url, classname="", icon_name=None, attrs={}, priority=1000 ): self.label = label self.url = url - self.classes = classes + self.classname = classname self.icon_name = icon_name self.attrs = attrs.copy() # if a 'title' attribute has been passed, correct that to aria-label @@ -30,7 +30,7 @@ class Button(Component): else: attrs = { "href": self.url, - "class": " ".join(sorted(self.classes)), + "class": self.classname, } attrs.update(self.attrs) return format_html("{}", flatatt(attrs), self.label) @@ -68,7 +68,7 @@ class Button(Component): return ( self.label == other.label and self.url == other.url - and self.classes == other.classes + and self.classname == other.classname and self.attrs == other.attrs and self.priority == other.priority ) @@ -77,9 +77,13 @@ class Button(Component): # Base class for all listing buttons # This is also used by SnippetListingButton defined in wagtail.snippets.widgets class ListingButton(Button): - def __init__(self, label, url, classes=set(), **kwargs): - classes = {"button", "button-small", "button-secondary"} | set(classes) - super().__init__(label, url, classes=classes, **kwargs) + def __init__(self, label, url, classname="", **kwargs): + if classname: + classname += " button button-small button-secondary" + else: + classname = "button button-small button-secondary" + + super().__init__(label, url, classname=classname, **kwargs) class PageListingButton(ListingButton): @@ -101,7 +105,7 @@ class BaseDropdownMenuButton(Button): "buttons": self.dropdown_buttons, "label": self.label, "title": self.aria_label, - "toggle_classname": " ".join(self.classes), + "toggle_classname": self.classname, "icon_name": self.icon_name, } diff --git a/wagtail/snippets/wagtail_hooks.py b/wagtail/snippets/wagtail_hooks.py index 81d2bf53b7..90ec074bb0 100644 --- a/wagtail/snippets/wagtail_hooks.py +++ b/wagtail/snippets/wagtail_hooks.py @@ -80,7 +80,6 @@ def register_snippet_listing_buttons(snippet, user, next_url=None): if viewset.inspect_view_enabled and permission_policy.user_has_any_permission( user, viewset.inspect_view_class.any_permission_required ): - yield SnippetListingButton( _("Inspect"), reverse( @@ -100,7 +99,7 @@ def register_snippet_listing_buttons(snippet, user, next_url=None): ), attrs={"aria-label": _("Delete '%(title)s'") % {"title": str(snippet)}}, priority=30, - classes=["no"], + classname="no", ) diff --git a/wagtail/users/wagtail_hooks.py b/wagtail/users/wagtail_hooks.py index 8e97e448c7..e10b41beb2 100644 --- a/wagtail/users/wagtail_hooks.py +++ b/wagtail/users/wagtail_hooks.py @@ -148,7 +148,7 @@ def user_listing_buttons(context, user): yield UserListingButton( _("Edit"), reverse("wagtailusers_users:edit", args=[user.pk]), - classes={"button-secondary"}, + classname="button-secondary", attrs={ "aria-label": _("Edit user '%(name)s'") % {"name": get_user_display_name(user)} @@ -159,7 +159,7 @@ def user_listing_buttons(context, user): yield UserListingButton( _("Delete"), reverse("wagtailusers_users:delete", args=[user.pk]), - classes={"no"}, + classname="no", attrs={ "aria-label": _("Delete user '%(name)s'") % {"name": get_user_display_name(user)} diff --git a/wagtail/users/widgets.py b/wagtail/users/widgets.py index 2c4e089560..da41f1d49f 100644 --- a/wagtail/users/widgets.py +++ b/wagtail/users/widgets.py @@ -2,6 +2,9 @@ from wagtail.admin.widgets import Button class UserListingButton(Button): - def __init__(self, label, url, classes=set(), **kwargs): - classes = {"button", "button-small"} | set(classes) - super().__init__(label, url, classes=classes, **kwargs) + def __init__(self, label, url, classname="", **kwargs): + if classname: + classname += " button button-small" + else: + classname = "button button-small" + super().__init__(label, url, classname=classname, **kwargs)