0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-30 01:46:24 +01:00

Replace 'classes' argument with a 'classname' string

as per https://docs.wagtail.org/en/stable/contributing/general_guidelines.html#use-classname-in-python-html-template-tag-variables
This commit is contained in:
Matt Westcott 2023-09-20 22:57:46 +01:00 committed by Matt Westcott
parent 26c2e686f1
commit f3adefe362
7 changed files with 29 additions and 23 deletions

View File

@ -1,7 +1,7 @@
{% load wagtailadmin_tags %}
{% for button in buttons %}
<a href="{{ button.url }}" aria-label="{{ button.aria_label }}" class="{{ button.classes|join:' ' }}">
<a href="{{ button.url }}" aria-label="{{ button.aria_label }}" class="{{ button.classname }}">
{% if button.icon_name %}
{% icon name=button.icon_name %}
{% endif %}

View File

@ -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
],

View File

@ -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):

View File

@ -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("<a{}>{}</a>", 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,
}

View File

@ -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",
)

View File

@ -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)}

View File

@ -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)