mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-04-13 11:30:59 +00:00
Merge pull request #411 from gasman/move_hooks_into_wagtailcore
Move the hooks subsystem into wagtailcore
This commit is contained in:
commit
6868d30ded
19 changed files with 67 additions and 62 deletions
|
|
@ -396,7 +396,7 @@ Registering functions with a Wagtail hook follows the following pattern:
|
|||
|
||||
.. code-block:: python
|
||||
|
||||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailcore import hooks
|
||||
|
||||
hooks.register('hook', function)
|
||||
|
||||
|
|
@ -409,7 +409,7 @@ Where ``'hook'`` is one of the following hook strings and ``function`` is a func
|
|||
|
||||
.. code-block:: python
|
||||
|
||||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailcore import hooks
|
||||
|
||||
class UserbarPuppyLinkItem(object):
|
||||
def render(self, request):
|
||||
|
|
@ -430,7 +430,7 @@ Where ``'hook'`` is one of the following hook strings and ``function`` is a func
|
|||
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailcore import hooks
|
||||
|
||||
class WelcomePanel(object):
|
||||
order = 50
|
||||
|
|
@ -456,7 +456,7 @@ Where ``'hook'`` is one of the following hook strings and ``function`` is a func
|
|||
|
||||
from django.http import HttpResponse
|
||||
|
||||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailcore import hooks
|
||||
|
||||
def do_after_page_create(request, page):
|
||||
return HttpResponse("Congrats on making content!", content_type="text/plain")
|
||||
|
|
@ -484,7 +484,7 @@ Where ``'hook'`` is one of the following hook strings and ``function`` is a func
|
|||
from django.http import HttpResponse
|
||||
from django.conf.urls import url
|
||||
|
||||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailcore import hooks
|
||||
|
||||
def admin_view( request ):
|
||||
return HttpResponse( \
|
||||
|
|
@ -506,7 +506,7 @@ Where ``'hook'`` is one of the following hook strings and ``function`` is a func
|
|||
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailcore import hooks
|
||||
from wagtail.wagtailadmin.menu import MenuItem
|
||||
|
||||
def construct_main_menu(request, menu_items):
|
||||
|
|
@ -526,7 +526,7 @@ Where ``'hook'`` is one of the following hook strings and ``function`` is a func
|
|||
from django.utils.html import format_html, format_html_join
|
||||
from django.conf import settings
|
||||
|
||||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailcore import hooks
|
||||
|
||||
def editor_js():
|
||||
js_files = [
|
||||
|
|
@ -554,7 +554,7 @@ Where ``'hook'`` is one of the following hook strings and ``function`` is a func
|
|||
from django.utils.html import format_html
|
||||
from django.conf import settings
|
||||
|
||||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailcore import hooks
|
||||
|
||||
def editor_css():
|
||||
return format_html('<link rel="stylesheet" href="' \
|
||||
|
|
@ -574,7 +574,7 @@ Where ``'hook'`` is one of the following hook strings and ``function`` is a func
|
|||
|
||||
.. code-block:: python
|
||||
|
||||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailcore import hooks
|
||||
from wagtail.wagtailcore.whitelist import attribute_rule, check_url, allow_without_attributes
|
||||
|
||||
def whitelister_element_rules():
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from django.conf.urls import url
|
|||
from django.core import urlresolvers
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailcore import hooks
|
||||
from wagtail.wagtailadmin.menu import MenuItem
|
||||
|
||||
from . import views
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailcore import hooks
|
||||
from wagtail.wagtailcore.whitelist import attribute_rule, check_url, allow_without_attributes
|
||||
|
||||
def editor_css():
|
||||
|
|
|
|||
|
|
@ -1,38 +1,4 @@
|
|||
from django.conf import settings
|
||||
try:
|
||||
from importlib import import_module
|
||||
except ImportError:
|
||||
# for Python 2.6, fall back on django.utils.importlib (deprecated as of Django 1.7)
|
||||
from django.utils.importlib import import_module
|
||||
# The 'hooks' module is now part of wagtailcore.
|
||||
# Imports are provided here for backwards compatibility
|
||||
|
||||
_hooks = {}
|
||||
|
||||
# TODO: support 'register' as a decorator:
|
||||
# @hooks.register('construct_main_menu')
|
||||
# def construct_main_menu(menu_items):
|
||||
# ...
|
||||
|
||||
|
||||
def register(hook_name, fn):
|
||||
if hook_name not in _hooks:
|
||||
_hooks[hook_name] = []
|
||||
_hooks[hook_name].append(fn)
|
||||
|
||||
_searched_for_hooks = False
|
||||
|
||||
|
||||
def search_for_hooks():
|
||||
global _searched_for_hooks
|
||||
if not _searched_for_hooks:
|
||||
for app_module in settings.INSTALLED_APPS:
|
||||
try:
|
||||
import_module('%s.wagtail_hooks' % app_module)
|
||||
except ImportError:
|
||||
continue
|
||||
|
||||
_searched_for_hooks = True
|
||||
|
||||
|
||||
def get_hooks(hook_name):
|
||||
search_for_hooks()
|
||||
return _hooks.get(hook_name, [])
|
||||
from wagtail.wagtailcore.hooks import register, get_hooks
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ from django import template
|
|||
from django.core import urlresolvers
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailadmin.menu import MenuItem
|
||||
|
||||
from wagtail.wagtailcore import hooks
|
||||
from wagtail.wagtailcore.models import get_navigation_menu_items, UserPagePermissionsProxy
|
||||
from wagtail.wagtailcore.utils import camelcase_to_underscore
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from django.conf.urls import url
|
|||
|
||||
from wagtail.wagtailadmin.forms import PasswordResetForm
|
||||
from wagtail.wagtailadmin.views import account, chooser, home, pages, tags, userbar
|
||||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailcore import hooks
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ from django.conf import settings
|
|||
from django.template import RequestContext
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailadmin.forms import SearchForm
|
||||
|
||||
from wagtail.wagtailcore import hooks
|
||||
from wagtail.wagtailcore.models import Page, PageRevision, UserPagePermissionsProxy
|
||||
|
||||
from wagtail.wagtaildocs.models import Document
|
||||
|
|
|
|||
|
|
@ -11,8 +11,9 @@ from django.views.decorators.vary import vary_on_headers
|
|||
|
||||
from wagtail.wagtailadmin.edit_handlers import TabbedInterface, ObjectList
|
||||
from wagtail.wagtailadmin.forms import SearchForm
|
||||
from wagtail.wagtailadmin import tasks, hooks, signals
|
||||
from wagtail.wagtailadmin import tasks, signals
|
||||
|
||||
from wagtail.wagtailcore import hooks
|
||||
from wagtail.wagtailcore.models import Page, PageRevision
|
||||
from wagtail.wagtailcore.signals import page_published
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from django.shortcuts import render
|
|||
from django.contrib.auth.decorators import permission_required
|
||||
|
||||
from wagtail.wagtailadmin.userbar import EditPageItem, AddPageItem, ApproveModerationEditPageItem, RejectModerationEditPageItem
|
||||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailcore import hooks
|
||||
from wagtail.wagtailcore.models import Page, PageRevision
|
||||
|
||||
|
||||
|
|
|
|||
38
wagtail/wagtailcore/hooks.py
Normal file
38
wagtail/wagtailcore/hooks.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
from django.conf import settings
|
||||
try:
|
||||
from importlib import import_module
|
||||
except ImportError:
|
||||
# for Python 2.6, fall back on django.utils.importlib (deprecated as of Django 1.7)
|
||||
from django.utils.importlib import import_module
|
||||
|
||||
_hooks = {}
|
||||
|
||||
# TODO: support 'register' as a decorator:
|
||||
# @hooks.register('construct_main_menu')
|
||||
# def construct_main_menu(menu_items):
|
||||
# ...
|
||||
|
||||
|
||||
def register(hook_name, fn):
|
||||
if hook_name not in _hooks:
|
||||
_hooks[hook_name] = []
|
||||
_hooks[hook_name].append(fn)
|
||||
|
||||
_searched_for_hooks = False
|
||||
|
||||
|
||||
def search_for_hooks():
|
||||
global _searched_for_hooks
|
||||
if not _searched_for_hooks:
|
||||
for app_module in settings.INSTALLED_APPS:
|
||||
try:
|
||||
import_module('%s.wagtail_hooks' % app_module)
|
||||
except ImportError:
|
||||
continue
|
||||
|
||||
_searched_for_hooks = True
|
||||
|
||||
|
||||
def get_hooks(hook_name):
|
||||
search_for_hooks()
|
||||
return _hooks.get(hook_name, [])
|
||||
|
|
@ -13,7 +13,7 @@ from wagtail.wagtaildocs.models import Document
|
|||
from wagtail.wagtailimages.models import get_image_model
|
||||
from wagtail.wagtailimages.formats import get_image_format
|
||||
|
||||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailcore import hooks
|
||||
|
||||
|
||||
# Define a set of 'embed handlers' and 'link handlers'. These handle the translation
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from django.core import urlresolvers
|
|||
from django.utils.html import format_html, format_html_join
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailcore import hooks
|
||||
from wagtail.wagtailadmin.menu import MenuItem
|
||||
|
||||
from wagtail.wagtaildocs import admin_urls
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from django.conf.urls import include, url
|
|||
from django.core import urlresolvers
|
||||
from django.utils.html import format_html
|
||||
|
||||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailcore import hooks
|
||||
from wagtail.wagtailembeds import urls
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from django.conf import settings
|
|||
from django.conf.urls import include, url
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailcore import hooks
|
||||
from wagtail.wagtailadmin.menu import MenuItem
|
||||
|
||||
from wagtail.wagtailforms import urls
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from django.core import urlresolvers
|
|||
from django.utils.html import format_html, format_html_join
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailcore import hooks
|
||||
from wagtail.wagtailadmin.menu import MenuItem
|
||||
|
||||
from wagtail.wagtailimages import urls
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from django.core import urlresolvers
|
|||
from django.conf.urls import include, url
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailcore import hooks
|
||||
from wagtail.wagtailredirects import urls
|
||||
|
||||
from wagtail.wagtailadmin.menu import MenuItem
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from django.core import urlresolvers
|
|||
from django.conf.urls import include, url
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailcore import hooks
|
||||
from wagtail.wagtailsearch.urls import admin as admin_urls
|
||||
|
||||
from wagtail.wagtailadmin.menu import MenuItem
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from django.core import urlresolvers
|
|||
from django.utils.html import format_html
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailcore import hooks
|
||||
from wagtail.wagtailadmin.menu import MenuItem
|
||||
|
||||
from wagtail.wagtailsnippets import urls
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from django.conf.urls import include, url
|
|||
from django.core import urlresolvers
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from wagtail.wagtailadmin import hooks
|
||||
from wagtail.wagtailcore import hooks
|
||||
from wagtail.wagtailadmin.menu import MenuItem
|
||||
|
||||
from wagtail.wagtailusers import urls
|
||||
|
|
|
|||
Loading…
Reference in a new issue