From 8b9b2ced36c641d08b364725f3ab4b530b5eaec3 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Wed, 14 Sep 2016 13:53:15 +0100 Subject: [PATCH] Docs for new hooks --- docs/reference/hooks.rst | 54 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/docs/reference/hooks.rst b/docs/reference/hooks.rst index f2872c3c4c..65973753cc 100644 --- a/docs/reference/hooks.rst +++ b/docs/reference/hooks.rst @@ -278,12 +278,12 @@ Hooks for customising the editing interface for pages and snippets. Add additional CSS files or snippets to all admin pages. .. code-block:: python - + from django.utils.html import format_html from django.contrib.staticfiles.templatetags.staticfiles import static - + from wagtail.wagtailcore import hooks - + @hooks.register('insert_global_admin_css') def global_admin_css(): return format_html('', static('my/wagtail/theme.css')) @@ -364,6 +364,34 @@ Hooks for customising the way users are directed through the process of creating return HttpResponse("Congrats on making content!", content_type="text/plain") +.. _before_create_page: + +``before_create_page`` +~~~~~~~~~~~~~~~~~~~~~ + + Called at the beginning of the "create page" view passing in the request, the parent page and page model class. + + The function does not have to return anything, but if an object with a ``status_code`` property is returned, Wagtail will use it as a response object and skip the rest of the view. + + Unlike, ``after_create_page``, this is run both for both ``GET`` and ``POST`` requests. + + This can be used to completely override the editor on a per-view basis: + + .. code-block:: python + + from django.http import HttpResponse + + from wagtail.wagtailcore import hooks + + from .models import AwesomePage + from .admin_views import edit_awesome_page + + @hooks.register('before_create_page') + def before_create_page(request, parent_page, page_class): + # Use a custom create view for the AwesomePage model + if page_class == AwesomePage: + return create_awesome_page(request, parent_page) + .. _after_delete_page: ``after_delete_page`` @@ -372,6 +400,16 @@ Hooks for customising the way users are directed through the process of creating Do something after a ``Page`` object is deleted. Uses the same behavior as ``after_create_page``. +.. _before_delete_page: + +``before_delete_page`` +~~~~~~~~~~~~~~~~~~~~~ + + Called at the beginning of the "delete page" view passing in the request and the page object. + + Uses the same behavior as ``before_create_page``. + + .. _after_edit_page: ``after_edit_page`` @@ -380,6 +418,16 @@ Hooks for customising the way users are directed through the process of creating Do something with a ``Page`` object after it has been updated. Uses the same behavior as ``after_create_page``. +.. _before_edit_page: + +``before_edit_page`` +~~~~~~~~~~~~~~~~~~~~~ + + Called at the beginning of the "edit page" view passing in the request and the page object. + + Uses the same behavior as ``before_create_page``. + + .. _construct_wagtail_userbar: ``construct_wagtail_userbar``