Add code example for `before_delete_page` hook

pull/7555/head
JaneLiu 2020-10-28 21:17:27 -04:00 zatwierdzone przez LB Johnston
rodzic 42da0b1083
commit 92381698d0
4 zmienionych plików z 22 dodań i 1 usunięć

Wyświetl plik

@ -29,6 +29,7 @@ Changelog
* Add `label_format` attribute to customise the label shown for a collapsed StructBlock (Matt Westcott)
* User Group permissions will now show all custom object permissions in one row instead of a separate table (Kamil Marut)User Group permissions editing in the admin will now show all custom object permissions in one row instead of a separate table (Kamil Marut)
* Create `ImageFileMixin` to extract shared file handling methods from `AbstractImage` and `AbstractRendition` (Fabien Le Frapper)
* Add `before_delete_page` example to Hooks documentation (Jane Liu)
* Fix: Delete button is now correct colour on snippets and modeladmin listings (Brandon Murch)
* Fix: Ensure that StreamBlock / ListBlock-level validation errors are counted towards error counts (Matt Westcott)
* Fix: InlinePanel add button is now keyboard navigatable (Jesse Menn)

Wyświetl plik

@ -541,6 +541,7 @@ Contributors
* Bryan Williams
* Wout De Puysseleir
* Kamil Marut
* Jane Liu
Translators
===========

Wyświetl plik

@ -605,8 +605,26 @@ Hooks for customising the way users are directed through the process of creating
Called at the beginning of the "delete page" view passing in the request and the page object.
Uses the same behaviour as ``before_create_page``.
Uses the same behaviour as ``before_create_page``, is is run both for both ``GET`` and ``POST`` requests.
.. code-block:: python
from django.shortcuts import redirect
from django.utils.html import format_html
from wagtail.admin import messages
from wagtail.core import hooks
from .models import AwesomePage
@hooks.register('before_delete_page')
def before_delete_page(request, page):
"""Block awesome page deletion and show a message."""
if request.method == 'POST' and page.specific_class in [AwesomePage]:
messages.warning(request, "Awesome pages cannot be deleted, only unpublished")
return redirect('wagtailadmin_pages:delete', page.pk)
.. _after_edit_page:

Wyświetl plik

@ -40,6 +40,7 @@ Other features
* Add ``label_format`` attribute to customise the label shown for a collapsed StructBlock (Matt Westcott)
* User Group permissions editing in the admin will now show all custom object permissions in one row instead of a separate table (Kamil Marut)
* Create ``ImageFileMixin`` to extract shared file handling methods from ``AbstractImage`` and ``AbstractRendition`` (Fabien Le Frapper)
* Add ``before_delete_page`` example to Hooks documentation (Jane Liu)
Bug fixes
~~~~~~~~~