kopia lustrzana https://github.com/wagtail/wagtail
Update docs to reflect snippet deletion hook changes
rodzic
f3637ad857
commit
909e7fedbf
|
@ -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.
|
||||
|
||||
```python
|
||||
from django.http import HttpResponse
|
||||
|
@ -1175,7 +1175,7 @@ from wagtail import hooks
|
|||
|
||||
@hooks.register('after_delete_snippet')
|
||||
def after_snippet_delete(request, instances):
|
||||
# "instances" is a QuerySet
|
||||
# "instances" is a list
|
||||
total = len(instances)
|
||||
return HttpResponse(f"{total} snippets have been deleted", content_type="text/plain")
|
||||
```
|
||||
|
@ -1184,7 +1184,7 @@ def after_snippet_delete(request, instances):
|
|||
|
||||
### `before_delete_snippet`
|
||||
|
||||
Called at the beginning of the delete snippet view. 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 at the beginning of the delete snippet view. 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.
|
||||
|
||||
```python
|
||||
from django.http import HttpResponse
|
||||
|
@ -1193,14 +1193,15 @@ from wagtail import hooks
|
|||
|
||||
@hooks.register('before_delete_snippet')
|
||||
def before_snippet_delete(request, instances):
|
||||
# "instances" is a QuerySet
|
||||
# "instances" is a list
|
||||
total = len(instances)
|
||||
|
||||
if request.method == 'POST':
|
||||
# Override the deletion behaviour
|
||||
instances.delete()
|
||||
for instance in instances:
|
||||
# Override the deletion behaviour
|
||||
instance.delete()
|
||||
|
||||
return HttpResponse(f"{total} snippets have been deleted", content_type="text/plain")
|
||||
return HttpResponse(f"{total} snippets have been deleted", content_type="text/plain")
|
||||
```
|
||||
|
||||
(register_snippet_action_menu_item)=
|
||||
|
|
|
@ -230,6 +230,7 @@ Stimulus [targets](https://stimulus.hotwired.dev/reference/targets) and [actions
|
|||
* `<button ... data-action="w-progress#activate:once" ...>` - only trigger the progress behaviour once
|
||||
* `<button ... data-action="readystatechange@document->w-progress#activate:once" data-w-progress-duration-value="5000" disabled ...>` - disabled on load (once JS starts) and becomes enabled after 5s duration
|
||||
|
||||
|
||||
### JavaScript `window.addMessages` replaced with event dispatching
|
||||
|
||||
The undocumented `window.addMessage` function is no longer available and will throw an error if called, if similar functionality is required use DOM Event dispatching instead as follows.
|
||||
|
@ -261,8 +262,18 @@ document.dispatchEvent(
|
|||
|
||||
Note that this event name may change in the future and this functionality is still not officially supported.
|
||||
|
||||
|
||||
### Changes to StreamField `ValidationError` classes
|
||||
|
||||
The client-side handling of StreamField validation errors has been updated. The JavaScript classes `StreamBlockValidationError`, `ListBlockValidationError`, `StructBlockValidationError` and `TypedTableBlockValidationError` have been removed, and the corresponding Python classes can no longer be serialised using Telepath. Instead, the `setError` methods on client-side block objects now accept a plain JSON representation of the error, obtained from the `as_json_data` method on the Python class. Custom JavaScript code that works with these objects must be updated accordingly.
|
||||
|
||||
Additionally, the Python `StreamBlockValidationError`, `ListBlockValidationError`, `StructBlockValidationError` and `TypedTableBlockValidationError` classes no longer provide a `params` dict with `block_errors` and `non_block_errors` items; these are now available as the attributes `block_errors` and `non_block_errors` on the exception itself (or `cell_errors` and `non_block_errors` in the case of `TypedTableBlockValidationError`).
|
||||
|
||||
|
||||
### Snippets `delete-multiple` view removed
|
||||
|
||||
The ability to remove multiple snippet instances from the `DeleteView` and the undocumented `wagtailsnippets_{app_label}_{model_name}:delete-multiple` URL pattern have been removed. The view's functionality has been replaced by the delete action of the bulk actions feature introduced in Wagtail 4.0.
|
||||
|
||||
The delete bulk action view now also calls the `{before,after}_delete_snippet` hooks, in addition to the `{before,after}_bulk_action` hooks.
|
||||
|
||||
If you have customised the `IndexView` and/or `DeleteView` views in a `SnippetViewSet` subclass, make sure that the `delete_multiple_url_name` attribute is renamed to `delete_url_name`.
|
||||
|
|
Ładowanie…
Reference in New Issue