kopia lustrzana https://github.com/wagtail/wagtail
added translate button to header actions dropdown, removed all the instances of is_parent
- Fixed failing tests, added check for simple_translations enabled - resolves #8866pull/8904/head
rodzic
2a751e9b00
commit
887a259723
|
@ -75,7 +75,7 @@ Changelog
|
|||
* Use new modal dialog component for privacy settings modal (Sage Abdullah)
|
||||
* Add `menu_item_name` to modify MenuItem's name for ModelAdmin (Alexander Rogovskyy, Vu Pham)
|
||||
* Add an extra confirmation prompt when deleting pages with a large number of child pages (Jaspreet Singh)
|
||||
* Adopt the slim header in page listing views, with buttons moved under the "Actions" dropdown (Paarth Agarwal)
|
||||
* Adopt the slim header in page listing views, with buttons moved under the "Actions" dropdown, including addition of translation page in the parent "more" button (Paarth Agarwal)
|
||||
* Improve help block styles in Windows High Contrast Mode with less reliance on communication via colour alone (Anuja Verma)
|
||||
* Add a bottom border to top messages so they stand out from the header (Anuja Verma)
|
||||
* Replace latin abbreviations (i.e. / e.g.) with common English phrases so that documentation is easier to understand (Dominik Lech)
|
||||
|
@ -85,6 +85,7 @@ Changelog
|
|||
* Remove undocumented `SearchableListMixin` (Sage Abdullah)
|
||||
* Extract filtering code from ReportView to generic IndexView (Sage Abdullah)
|
||||
* Retain other query params in header search behaviour (Sage Abdullah)
|
||||
* Remove `is_parent` kwarg in various page button hooks as this approach is no longer required (Paarth Agarwal)
|
||||
* Fix: Typo in `ResumeWorkflowActionFormatter` message (Stefan Hammer)
|
||||
* Fix: Throw a meaningful error when saving an image to an unrecognised image format (Christian Franke)
|
||||
* Fix: Remove extra padding for headers with breadcrumbs on mobile viewport (Steven Steinwand)
|
||||
|
|
|
@ -53,7 +53,7 @@ to allow a single author to be specified for each post.
|
|||
author_modeladmin = AuthorModelAdmin()
|
||||
|
||||
@hooks.register('register_page_listing_buttons')
|
||||
def add_author_edit_buttons(page, page_perms, is_parent=False, next_url=None):
|
||||
def add_author_edit_buttons(page, page_perms, next_url=None):
|
||||
"""
|
||||
For pages that have an author, add an additional button to the page listing,
|
||||
linking to the 'edit' page for that author.
|
||||
|
|
|
@ -795,9 +795,9 @@ Modify the final list of page listing buttons in the page explorer. The callable
|
|||
|
||||
```python
|
||||
@hooks.register('construct_page_listing_buttons')
|
||||
def remove_page_listing_button_item(buttons, page, page_perms, is_parent=False, context=None):
|
||||
if is_parent:
|
||||
buttons.pop() # removes the last 'more' dropdown button on the parent page listing buttons
|
||||
def remove_page_listing_button_item(buttons, page, page_perms, context=None):
|
||||
if page.is_root:
|
||||
buttons.pop() # removes the last 'more' dropdown button on the root page listing buttons
|
||||
```
|
||||
|
||||
(construct_wagtail_userbar)=
|
||||
|
@ -977,7 +977,7 @@ This example will add a simple button to the listing:
|
|||
from wagtail.admin import widgets as wagtailadmin_widgets
|
||||
|
||||
@hooks.register('register_page_listing_buttons')
|
||||
def page_listing_buttons(page, page_perms, is_parent=False, next_url=None):>
|
||||
def page_listing_buttons(page, page_perms, next_url=None):
|
||||
yield wagtailadmin_widgets.PageListingButton(
|
||||
'A page listing button',
|
||||
'/goes/to/a/url/',
|
||||
|
@ -989,7 +989,6 @@ The arguments passed to the hook are as follows:
|
|||
|
||||
- `page` - the page object to generate the button for
|
||||
- `page_perms` - a `PagePermissionTester` object that can be queried to determine the current user's permissions on the given page
|
||||
- `is_parent` - if true, this button is being rendered for the parent page being displayed at the top of the listing
|
||||
- `next_url` - the URL that the linked action should redirect back to on completion of the action, if the view supports it
|
||||
|
||||
The `priority` argument controls the order the buttons are displayed in. Buttons are ordered from low to high priority, so a button with `priority=10` will be displayed before a button with `priority=20`.
|
||||
|
@ -1006,7 +1005,7 @@ This example will add a simple button to the dropdown menu:
|
|||
from wagtail.admin import widgets as wagtailadmin_widgets
|
||||
|
||||
@hooks.register('register_page_listing_more_buttons')
|
||||
def page_listing_more_buttons(page, page_perms, is_parent=False, next_url=None):
|
||||
def page_listing_more_buttons(page, page_perms, next_url=None):
|
||||
yield wagtailadmin_widgets.Button(
|
||||
'A dropdown button',
|
||||
'/goes/to/a/url/',
|
||||
|
@ -1018,7 +1017,6 @@ The arguments passed to the hook are as follows:
|
|||
|
||||
- `page` - the page object to generate the button for
|
||||
- `page_perms` - a `PagePermissionTester` object that can be queried to determine the current user's permissions on the given page
|
||||
- `is_parent` - if true, this button is being rendered for the parent page being displayed at the top of the listing
|
||||
- `next_url` - the URL that the linked action should redirect back to on completion of the action, if the view supports it
|
||||
|
||||
The `priority` argument controls the order the buttons are displayed in the dropdown. Buttons are ordered from low to high priority, so a button with `priority=10` will be displayed before a button with `priority=60`.
|
||||
|
@ -1036,19 +1034,18 @@ This example shows how Wagtail's default admin dropdown is implemented. You can
|
|||
from wagtail.admin import widgets as wagtailadmin_widgets
|
||||
|
||||
@hooks.register('register_page_listing_buttons')
|
||||
def page_custom_listing_buttons(page, page_perms, is_parent=False, next_url=None):
|
||||
def page_custom_listing_buttons(page, page_perms, next_url=None):
|
||||
yield wagtailadmin_widgets.ButtonWithDropdownFromHook(
|
||||
'More actions',
|
||||
hook_name='my_button_dropdown_hook',
|
||||
page=page,
|
||||
page_perms=page_perms,
|
||||
is_parent=is_parent,
|
||||
next_url=next_url,
|
||||
priority=50
|
||||
)
|
||||
|
||||
@hooks.register('my_button_dropdown_hook')
|
||||
def page_custom_listing_more_buttons(page, page_perms, is_parent=False, next_url=None):
|
||||
def page_custom_listing_more_buttons(page, page_perms, next_url=None):
|
||||
if page_perms.can_move():
|
||||
yield wagtailadmin_widgets.Button('Move', reverse('wagtailadmin_pages:move', args=[page.id]), priority=10)
|
||||
if page_perms.can_delete():
|
||||
|
|
|
@ -110,10 +110,11 @@ In Wagtail 2.16, we introduced support for Windows High Contrast mode (WHCM). Th
|
|||
* Use new modal dialog component for privacy settings modal (Sage Abdullah)
|
||||
* Add `menu_item_name` to modify MenuItem's name for ModelAdmin (Alexander Rogovskyy, Vu Pham)
|
||||
* Add an extra confirmation prompt when deleting pages with a large number of child pages (Jaspreet Singh)
|
||||
* Adopt the slim header in page listing views, with buttons moved under the "Actions" dropdown (Paarth Agarwal)
|
||||
* Adopt the slim header in page listing views, with buttons moved under the "Actions" dropdown, including addition of translation page in the parent "more" button (Paarth Agarwal)
|
||||
* Replace latin abbreviations (i.e. / e.g.) with common English phrases so that documentation is easier to understand (Dominik Lech)
|
||||
* Add shortcut for accessing StreamField blocks by block name with new [`blocks_by_name` and `first_block_by_name` methods on `StreamValue`](streamfield_retrieving_blocks_by_name) (Tidiane Dia, Matt Westcott)
|
||||
* Add HTML-aware max_length validation on RichTextField and RichTextBlock (Matt Westcott)
|
||||
* Remove `is_parent` kwarg in various page button hooks as this approach is no longer required (Paarth Agarwal)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
|
@ -242,6 +243,11 @@ The page explorer listings now use Wagtail’s new slim header, replacing the pr
|
|||
|
||||
Customising which actions are available and adding extra actions is still possible, but has to be done with the [`register_page_header_buttons`](register_page_header_buttons) hook, rather than [`register_page_listing_buttons`](register_page_listing_buttons) and [`register_page_listing_more_buttons`](register_page_listing_more_buttons). Those hooks still work as-is to define actions for each page within the listings.
|
||||
|
||||
### `is_parent` removed from page button hooks
|
||||
|
||||
* The following hooks `construct_page_listing_buttons`, `register_page_listing_buttons`, `register_page_listing_more_buttons` no longer accept the `is_parent` keyword argument and this should be removed.
|
||||
* `is_parent` was the previous approach for determining whether the buttons would show in the listing rows or the page's more button, this can be now achieved with discrete hooks instead.
|
||||
|
||||
### Changed CSS variables for admin colour themes
|
||||
|
||||
As part of our support for theming across all colors, we’ve had to rename or remove some of the pre-existing CSS variables. Wagtail’s indigo is now customisable with `--w-color-primary`, and the teal is customisable as `--w-color-secondary`. See [](custom_user_interface_colours) for an overview of all customisable colours. Here are replaced variables:
|
||||
|
|
|
@ -477,18 +477,18 @@ def paginate(context, page, base_url="", page_key="p", classnames=""):
|
|||
|
||||
|
||||
@register.inclusion_tag("wagtailadmin/pages/listing/_buttons.html", takes_context=True)
|
||||
def page_listing_buttons(context, page, page_perms, is_parent=False):
|
||||
def page_listing_buttons(context, page, page_perms):
|
||||
next_url = context.request.path
|
||||
button_hooks = hooks.get_hooks("register_page_listing_buttons")
|
||||
|
||||
buttons = []
|
||||
for hook in button_hooks:
|
||||
buttons.extend(hook(page, page_perms, is_parent, next_url))
|
||||
buttons.extend(hook(page, page_perms, next_url))
|
||||
|
||||
buttons.sort()
|
||||
|
||||
for hook in hooks.get_hooks("construct_page_listing_buttons"):
|
||||
hook(buttons, page, page_perms, is_parent, context)
|
||||
hook(buttons, page, page_perms, context)
|
||||
|
||||
return {"page": page, "buttons": buttons}
|
||||
|
||||
|
@ -585,7 +585,6 @@ def bulk_action_choices(context, app_label, model_name):
|
|||
for action in bulk_action_more_list
|
||||
],
|
||||
)
|
||||
more_button.is_parent = True
|
||||
bulk_action_buttons.append(more_button)
|
||||
|
||||
return {"buttons": bulk_action_buttons}
|
||||
|
|
|
@ -1278,7 +1278,7 @@ class TestPageEdit(TestCase, WagtailTestUtils):
|
|||
)
|
||||
|
||||
def test_page_edit_num_queries(self):
|
||||
with self.assertNumQueries(38):
|
||||
with self.assertNumQueries(40):
|
||||
self.client.get(
|
||||
reverse("wagtailadmin_pages:edit", args=(self.event_page.id,))
|
||||
)
|
||||
|
|
|
@ -54,7 +54,7 @@ class TestButtonsHooks(TestCase, WagtailTestUtils):
|
|||
)
|
||||
|
||||
def test_register_page_listing_buttons(self):
|
||||
def page_listing_buttons(page, page_perms, is_parent=False, next_url=None):
|
||||
def page_listing_buttons(page, page_perms, next_url=None):
|
||||
yield wagtailadmin_widgets.PageListingButton(
|
||||
"Another useless page listing button", "/custom-url", priority=10
|
||||
)
|
||||
|
@ -75,7 +75,7 @@ class TestButtonsHooks(TestCase, WagtailTestUtils):
|
|||
self.assertContains(response, "Another useless page listing button")
|
||||
|
||||
def test_register_page_listing_more_buttons(self):
|
||||
def page_listing_more_buttons(page, page_perms, is_parent=False, next_url=None):
|
||||
def page_listing_more_buttons(page, page_perms, next_url=None):
|
||||
yield wagtailadmin_widgets.Button(
|
||||
'Another useless button in default "More" dropdown',
|
||||
"/custom-url",
|
||||
|
@ -100,23 +100,18 @@ class TestButtonsHooks(TestCase, WagtailTestUtils):
|
|||
)
|
||||
|
||||
def test_custom_button_with_dropdown(self):
|
||||
def page_custom_listing_buttons(
|
||||
page, page_perms, is_parent=False, next_url=None
|
||||
):
|
||||
def page_custom_listing_buttons(page, page_perms, next_url=None):
|
||||
yield wagtailadmin_widgets.ButtonWithDropdownFromHook(
|
||||
"One more more button",
|
||||
hook_name="register_page_listing_one_more_more_buttons",
|
||||
page=page,
|
||||
page_perms=page_perms,
|
||||
is_parent=is_parent,
|
||||
next_url=next_url,
|
||||
attrs={"target": "_blank", "rel": "noreferrer"},
|
||||
priority=50,
|
||||
)
|
||||
|
||||
def page_custom_listing_more_buttons(
|
||||
page, page_perms, is_parent=False, next_url=None
|
||||
):
|
||||
def page_custom_listing_more_buttons(page, page_perms, next_url=None):
|
||||
yield wagtailadmin_widgets.Button(
|
||||
'Another useless dropdown button in "One more more button" dropdown',
|
||||
"/custom-url",
|
||||
|
@ -175,18 +170,14 @@ class TestButtonsHooks(TestCase, WagtailTestUtils):
|
|||
|
||||
# page_listing_more_button generator yields only `Delete button`
|
||||
delete_button = next(
|
||||
page_listing_more_buttons(
|
||||
page, page_perms, is_parent=False, next_url=next_url
|
||||
)
|
||||
page_listing_more_buttons(page, page_perms, next_url=next_url)
|
||||
)
|
||||
|
||||
self.assertEqual(delete_button.url, full_url)
|
||||
|
||||
next_url = reverse("wagtailadmin_explore", args=[page.id])
|
||||
delete_button = next(
|
||||
page_listing_more_buttons(
|
||||
page, page_perms, is_parent=False, next_url=next_url
|
||||
)
|
||||
page_listing_more_buttons(page, page_perms, next_url=next_url)
|
||||
)
|
||||
|
||||
self.assertEqual(delete_button.url, base_url)
|
||||
|
@ -196,13 +187,11 @@ class TestButtonsHooks(TestCase, WagtailTestUtils):
|
|||
page_perms = BasePagePerms()
|
||||
|
||||
# no button returned
|
||||
buttons = page_listing_more_buttons(page, page_perms, is_parent=True)
|
||||
buttons = page_listing_more_buttons(page, page_perms)
|
||||
self.assertEqual(len(list(buttons)), 0)
|
||||
|
||||
page_perms = ReorderOnlyPagePerms()
|
||||
# page_listing_more_button generator yields only `Sort menu order button`
|
||||
reorder_button = next(
|
||||
page_listing_more_buttons(page, page_perms, is_parent=True)
|
||||
)
|
||||
reorder_button = next(page_listing_more_buttons(page, page_perms))
|
||||
|
||||
self.assertEqual(reorder_button.url, "?ordering=ord")
|
||||
|
|
|
@ -45,7 +45,14 @@ from wagtail.admin.views.pages.bulk_actions import (
|
|||
)
|
||||
from wagtail.admin.viewsets import viewsets
|
||||
from wagtail.admin.widgets import Button, ButtonWithDropdownFromHook, PageListingButton
|
||||
from wagtail.models import Collection, Page, Task, UserPagePermissionsProxy, Workflow
|
||||
from wagtail.models import (
|
||||
Collection,
|
||||
Locale,
|
||||
Page,
|
||||
Task,
|
||||
UserPagePermissionsProxy,
|
||||
Workflow,
|
||||
)
|
||||
from wagtail.permissions import (
|
||||
collection_permission_policy,
|
||||
task_permission_policy,
|
||||
|
@ -200,7 +207,7 @@ def register_workflow_tasks_menu_item():
|
|||
|
||||
|
||||
@hooks.register("register_page_listing_buttons")
|
||||
def page_listing_buttons(page, page_perms, is_parent=False, next_url=None):
|
||||
def page_listing_buttons(page, page_perms, next_url=None):
|
||||
if page_perms.can_edit():
|
||||
yield PageListingButton(
|
||||
_("Edit"),
|
||||
|
@ -234,41 +241,21 @@ def page_listing_buttons(page, page_perms, is_parent=False, next_url=None):
|
|||
priority=30,
|
||||
)
|
||||
if page_perms.can_add_subpage():
|
||||
if is_parent:
|
||||
yield Button(
|
||||
_("Add child page"),
|
||||
reverse("wagtailadmin_pages:add_subpage", args=[page.id]),
|
||||
attrs={
|
||||
"aria-label": _("Add a child page to '%(title)s' ")
|
||||
% {"title": page.get_admin_display_title()},
|
||||
},
|
||||
classes={
|
||||
"button",
|
||||
"button-small",
|
||||
"bicolor",
|
||||
"icon",
|
||||
"white",
|
||||
"icon-plus",
|
||||
},
|
||||
priority=40,
|
||||
)
|
||||
else:
|
||||
yield PageListingButton(
|
||||
_("Add child page"),
|
||||
reverse("wagtailadmin_pages:add_subpage", args=[page.id]),
|
||||
attrs={
|
||||
"aria-label": _("Add a child page to '%(title)s' ")
|
||||
% {"title": page.get_admin_display_title()}
|
||||
},
|
||||
priority=40,
|
||||
)
|
||||
yield PageListingButton(
|
||||
_("Add child page"),
|
||||
reverse("wagtailadmin_pages:add_subpage", args=[page.id]),
|
||||
attrs={
|
||||
"aria-label": _("Add a child page to '%(title)s' ")
|
||||
% {"title": page.get_admin_display_title()}
|
||||
},
|
||||
priority=40,
|
||||
)
|
||||
|
||||
yield ButtonWithDropdownFromHook(
|
||||
_("More"),
|
||||
hook_name="register_page_listing_more_buttons",
|
||||
page=page,
|
||||
page_perms=page_perms,
|
||||
is_parent=is_parent,
|
||||
next_url=next_url,
|
||||
attrs={
|
||||
"target": "_blank",
|
||||
|
@ -281,7 +268,7 @@ def page_listing_buttons(page, page_perms, is_parent=False, next_url=None):
|
|||
|
||||
|
||||
@hooks.register("register_page_listing_more_buttons")
|
||||
def page_listing_more_buttons(page, page_perms, is_parent=False, next_url=None):
|
||||
def page_listing_more_buttons(page, page_perms, next_url=None):
|
||||
if page_perms.can_move():
|
||||
yield Button(
|
||||
_("Move"),
|
||||
|
@ -350,7 +337,7 @@ def page_listing_more_buttons(page, page_perms, is_parent=False, next_url=None):
|
|||
priority=50,
|
||||
)
|
||||
|
||||
if is_parent and page_perms.can_reorder_children():
|
||||
if page_perms.can_reorder_children():
|
||||
yield Button(
|
||||
_("Sort menu order"),
|
||||
"?ordering=ord",
|
||||
|
@ -363,7 +350,7 @@ def page_listing_more_buttons(page, page_perms, is_parent=False, next_url=None):
|
|||
|
||||
|
||||
@hooks.register("register_page_header_buttons")
|
||||
def page_header_buttons(page, page_perms, is_parent=False, next_url=None):
|
||||
def page_header_buttons(page, page_perms, next_url=None):
|
||||
if page_perms.can_edit():
|
||||
yield Button(
|
||||
_("Edit"),
|
||||
|
@ -447,7 +434,7 @@ def page_header_buttons(page, page_perms, is_parent=False, next_url=None):
|
|||
},
|
||||
priority=60,
|
||||
)
|
||||
if is_parent and page_perms.can_reorder_children():
|
||||
if page_perms.can_reorder_children():
|
||||
url = reverse("wagtailadmin_explore", args=[page.id])
|
||||
url += "?ordering=ord"
|
||||
yield Button(
|
||||
|
@ -460,6 +447,34 @@ def page_header_buttons(page, page_perms, is_parent=False, next_url=None):
|
|||
},
|
||||
priority=70,
|
||||
)
|
||||
if Permission.objects.filter(
|
||||
content_type__app_label="simple_translation", codename="submit_translation"
|
||||
):
|
||||
if (
|
||||
page_perms.user.has_perm("simple_translation.submit_translation")
|
||||
and not page.is_root()
|
||||
):
|
||||
# If there's at least one locale that we haven't translated into yet, show "Translate this page" button
|
||||
has_locale_to_translate_to = Locale.objects.exclude(
|
||||
id__in=page.get_translations(inclusive=True).values_list(
|
||||
"locale_id", flat=True
|
||||
)
|
||||
).exists()
|
||||
|
||||
if has_locale_to_translate_to:
|
||||
url = reverse(
|
||||
"simple_translation:submit_page_translation", args=[page.id]
|
||||
)
|
||||
yield Button(
|
||||
_("Translate"),
|
||||
url,
|
||||
icon_name="globe",
|
||||
attrs={
|
||||
"title": _("Translate this page")
|
||||
% {"title": page.get_admin_display_title()}
|
||||
},
|
||||
priority=80,
|
||||
)
|
||||
|
||||
|
||||
@hooks.register("register_admin_urls")
|
||||
|
|
|
@ -79,7 +79,6 @@ class BaseDropdownMenuButton(Button):
|
|||
"buttons": self.dropdown_buttons,
|
||||
"label": self.label,
|
||||
"title": self.attrs.get("title"),
|
||||
"is_parent": self.is_parent,
|
||||
}
|
||||
|
||||
def render(self):
|
||||
|
@ -108,13 +107,10 @@ class ButtonWithDropdown(BaseDropdownMenuButton):
|
|||
class ButtonWithDropdownFromHook(BaseDropdownMenuButton):
|
||||
template_name = "wagtailadmin/pages/listing/_button_with_dropdown.html"
|
||||
|
||||
def __init__(
|
||||
self, label, hook_name, page, page_perms, is_parent, next_url=None, **kwargs
|
||||
):
|
||||
def __init__(self, label, hook_name, page, page_perms, next_url=None, **kwargs):
|
||||
self.hook_name = hook_name
|
||||
self.page = page
|
||||
self.page_perms = page_perms
|
||||
self.is_parent = is_parent
|
||||
self.next_url = next_url
|
||||
|
||||
super().__init__(label, **kwargs)
|
||||
|
@ -129,9 +125,7 @@ class ButtonWithDropdownFromHook(BaseDropdownMenuButton):
|
|||
|
||||
buttons = []
|
||||
for hook in button_hooks:
|
||||
buttons.extend(
|
||||
hook(self.page, self.page_perms, self.is_parent, self.next_url)
|
||||
)
|
||||
buttons.extend(hook(self.page, self.page_perms, self.next_url))
|
||||
|
||||
buttons.sort()
|
||||
return buttons
|
||||
|
|
|
@ -48,7 +48,7 @@ def register_submit_translation_permission():
|
|||
|
||||
|
||||
@hooks.register("register_page_listing_more_buttons")
|
||||
def page_listing_more_buttons(page, page_perms, is_parent=False, next_url=None):
|
||||
def page_listing_more_buttons(page, page_perms, next_url=None):
|
||||
if (
|
||||
page_perms.user.has_perm("simple_translation.submit_translation")
|
||||
and not page.is_root()
|
||||
|
|
|
@ -165,9 +165,7 @@ def register_relax_menu_item(menu_items, request, context):
|
|||
|
||||
|
||||
@hooks.register("construct_page_listing_buttons")
|
||||
def register_page_listing_button_item(
|
||||
buttons, page, page_perms, is_parent=False, context=None
|
||||
):
|
||||
def register_page_listing_button_item(buttons, page, page_perms, context=None):
|
||||
item = Button(
|
||||
label="Dummy Button",
|
||||
url="/dummy-button",
|
||||
|
|
Ładowanie…
Reference in New Issue