0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Rename construct_wagtail_edit_bird hook

This commit is contained in:
Dan Braghis 2015-04-03 13:36:32 +01:00
parent 3fcf04f8a3
commit c174de8724
2 changed files with 23 additions and 3 deletions

View File

@ -46,9 +46,9 @@ The available hooks are:
return HttpResponse("<h1>bad googlebot no cookie</h1>") return HttpResponse("<h1>bad googlebot no cookie</h1>")
.. _construct_wagtail_edit_bird: .. _construct_wagtail_userbar:
``construct_wagtail_edit_bird`` ``construct_wagtail_userbar``
Add or remove items from the wagtail userbar. Add, edit, and moderation tools are provided by default. The callable passed into the hook must take the ``request`` object and a list of menu objects, ``items``. The menu item objects must have a ``render`` method which can take a ``request`` object and return the HTML string representing the menu item. See the userbar templates and menu item classes for more information. Add or remove items from the wagtail userbar. Add, edit, and moderation tools are provided by default. The callable passed into the hook must take the ``request`` object and a list of menu objects, ``items``. The menu item objects must have a ``render`` method which can take a ``request`` object and return the HTML string representing the menu item. See the userbar templates and menu item classes for more information.
.. code-block:: python .. code-block:: python
@ -60,7 +60,7 @@ The available hooks are:
return '<li><a href="http://cuteoverload.com/tag/puppehs/" ' \ return '<li><a href="http://cuteoverload.com/tag/puppehs/" ' \
+ 'target="_parent" class="action icon icon-wagtail">Puppies!</a></li>' + 'target="_parent" class="action icon icon-wagtail">Puppies!</a></li>'
@hooks.register('construct_wagtail_edit_bird') @hooks.register('construct_wagtail_userbar')
def add_puppy_link_item(request, items): def add_puppy_link_item(request, items):
return items.append( UserbarPuppyLinkItem() ) return items.append( UserbarPuppyLinkItem() )

View File

@ -1,3 +1,5 @@
import warnings
from django.shortcuts import render from django.shortcuts import render
from django.contrib.auth.decorators import permission_required from django.contrib.auth.decorators import permission_required
@ -5,6 +7,8 @@ from wagtail.wagtailadmin.userbar import EditPageItem, AddPageItem, ApproveModer
from wagtail.wagtailcore import hooks from wagtail.wagtailcore import hooks
from wagtail.wagtailcore.models import Page, PageRevision from wagtail.wagtailcore.models import Page, PageRevision
from wagtail.utils.deprecation import RemovedInWagtail11Warning
@permission_required('wagtailadmin.access_admin', raise_exception=True) @permission_required('wagtailadmin.access_admin', raise_exception=True)
def for_frontend(request, page_id): def for_frontend(request, page_id):
@ -16,6 +20,14 @@ def for_frontend(request, page_id):
for fn in hooks.get_hooks('construct_wagtail_edit_bird'): for fn in hooks.get_hooks('construct_wagtail_edit_bird'):
fn(request, items) fn(request, items)
warnings.warn(
"The 'construct_wagtail_edit_bird' hook has been renamed to 'construct_wagtail_userbar'."
"Please update function '%s' in '%s'." % (fn.__name__, fn.__module__), RemovedInWagtail11Warning
)
for fn in hooks.get_hooks('construct_wagtail_userbar'):
fn(request, items)
# Render the items # Render the items
rendered_items = [item.render(request) for item in items] rendered_items = [item.render(request) for item in items]
@ -40,6 +52,14 @@ def for_moderation(request, revision_id):
for fn in hooks.get_hooks('construct_wagtail_edit_bird'): for fn in hooks.get_hooks('construct_wagtail_edit_bird'):
fn(request, items) fn(request, items)
warnings.warn(
"The 'construct_wagtail_edit_bird' hook has been renamed to 'construct_wagtail_userbar'."
"Please update function '%s' in '%s'." % (fn.__name__, fn.__module__), RemovedInWagtail11Warning
)
for fn in hooks.get_hooks('construct_wagtail_userbar'):
fn(request, items)
# Render the items # Render the items
rendered_items = [item.render(request) for item in items] rendered_items = [item.render(request) for item in items]