New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove unused snippets delete-multiple view #10099
Conversation
Manage this branch in SquashTest this branch here: https://laymonageremove-unused-b5e1h.squash.io |
e8db6bc
to
a7728f9
Compare
a7728f9
to
4820a3d
Compare
@@ -1166,7 +1166,7 @@ Called at the beginning of the create snippet view. Works in a similar way to `b | |||
|
|||
### `after_delete_snippet` | |||
|
|||
Called when a Snippet is deleted. The callable passed into the hook will receive the model instance(s) as a queryset along with the request object. If the callable returns an `HttpResponse`, that response will be returned immediately to the user, and Wagtail will not proceed to call `redirect()` to the listing view. | |||
Called when a Snippet is deleted. The callable passed into the hook will receive the model instance(s) as a list along with the request object. If the callable returns an `HttpResponse`, that response will be returned immediately to the user, and Wagtail will not proceed to call `redirect()` to the listing view. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has never been consistent since the hooks were introduced: if there's only one snippet to be deleted, the hook is called with a list, and a queryset otherwise.
The base bulk action view doesn't store a reference to the queryset, it's immediately evaluated and the items are checked for permissions, so we can't call the hook with the queryset:
wagtail/wagtail/admin/views/bulk_action/base_bulk_action.py
Lines 93 to 107 in 0187a14
def get_actionable_objects(self): | |
objects = [] | |
items_with_no_access = [] | |
object_ids = self.request.GET.getlist("id") | |
if "all" in object_ids: | |
object_ids = self.get_all_objects_in_listing_query( | |
self.request.GET.get("childOf") | |
) | |
for obj in self.get_queryset(self.model, object_ids): | |
if not self.check_perm(obj): | |
items_with_no_access.append(obj) | |
else: | |
objects.append(obj) | |
return objects, {"items_with_no_access": items_with_no_access} |
I was thinking of storing the result in self.queryset
somewhere, but weirdly the method is a classmethod
:
wagtail/wagtail/admin/views/bulk_action/base_bulk_action.py
Lines 53 to 55 in 0187a14
@classmethod | |
def get_queryset(cls, model, object_ids): | |
return get_list_or_404(model, pk__in=object_ids) |
And it uses get_list_or_404
, which returns a list instead of a QuerySet
.
I'm cautious to make any changes to the base bulk action view as it seems out of scope for this PR. Considering that this hook has been partially lost since 4.0, I think having this consistently be a list isn't so bad.
I considered adding a .. versionchanged
here but I'm not sure what's the right way to document this, seeing that the hook has never been consistent, and the fact that it hasn't been accessible since 4.0.
@@ -6,5 +6,6 @@ | |||
<form action="{{ view.get_delete_url }}" method="POST"> | |||
{% csrf_token %} | |||
<input type="submit" value="{% trans 'Yes, delete' %}" class="button serious" /> | |||
<a href="{{ view.get_success_url }}" class="button button-secondary">{% trans "No, don't delete" %}</a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised this wasn't here before.
I added this so that the snippet delete template can reuse as much of the template as possible, so that I can fully reuse this in #10072
display_name = _("Delete") | ||
action_type = "delete" | ||
aria_label = _("Delete selected snippets") | ||
template_name = "wagtailsnippets/bulk_actions/confirm_bulk_delete.html" | ||
action_priority = 30 | ||
classes = {"serious"} | ||
|
||
@cached_property | ||
def _actionable_objects(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit tangled but I recommend reading the base bulk action view to see why I wrote it this way. In short, the base view's override points aren't as good as they could be.
def run_before_hook(self): | ||
# The method returns a tuple of | ||
# `(objects, {"items_with_no_access": items_with_no_access})`, hence [0] | ||
objects = self.get_actionable_objects()[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also be self._actionable_objects[0]
, but that would bypass get_actionable_objects()
if it has been overridden.
4820a3d
to
353646f
Compare
FYI @gasman The hooks situation in summary:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All looks good to me!
Merged in 909e7fe |
Fixes #10058.
Please check the following:
make lint
from the Wagtail root.Please describe additional details for testing this change.
Footnotes
Development Testing ↩
Browser and device support ↩
Accessibility Target ↩