kopia lustrzana https://github.com/wagtail/wagtail
				
				
				
			Add code example for `before_delete_page` hook
							rodzic
							
								
									42da0b1083
								
							
						
					
					
						commit
						92381698d0
					
				|  | @ -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) | ||||
|  |  | |||
|  | @ -541,6 +541,7 @@ Contributors | |||
| * Bryan Williams | ||||
| * Wout De Puysseleir | ||||
| * Kamil Marut | ||||
| * Jane Liu | ||||
| 
 | ||||
| Translators | ||||
| =========== | ||||
|  |  | |||
|  | @ -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: | ||||
| 
 | ||||
|  |  | |||
|  | @ -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 | ||||
| ~~~~~~~~~ | ||||
|  |  | |||
		Ładowanie…
	
		Reference in New Issue
	
	 JaneLiu
						JaneLiu