本文整理汇总了Python中wagtail.core.hooks.get_hooks方法的典型用法代码示例。如果您正苦于以下问题:Python hooks.get_hooks方法的具体用法?Python hooks.get_hooks怎么用?Python hooks.get_hooks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wagtail.core.hooks
的用法示例。
在下文中一共展示了hooks.get_hooks方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from wagtail.core import hooks [as 别名]
# 或者: from wagtail.core.hooks import get_hooks [as 别名]
def get(self, request, *args, **kwargs):
site = Site.find_for_request(request)
if not site:
raise Http404
if request.resolver_match.url_name == 'entry_page_serve_slug':
# Splitting the request path and obtaining the path_components
# this way allows you to place the blog at the level you want on
# your sitemap.
# Example:
# splited_path = ['es', 'blog', '2016', '06', '23', 'blog-entry']
# slicing this way you obtain:
# path_components = ['es', 'blog', 'blog-entry']
# with the oldest solution you'll get ['es', 'blog-entry']
# and a 404 will be raised
splited_path = strip_prefix_and_ending_slash(request.path).split("/")
path_components = splited_path[:-4] + splited_path[-1:]
else:
path_components = [strip_prefix_and_ending_slash(request.path).split('/')[-1]]
page, args, kwargs = site.root_page.specific.route(request, path_components)
for fn in hooks.get_hooks('before_serve_page'):
result = fn(page, request, args, kwargs)
if isinstance(result, HttpResponse):
return result
return page.serve(request, *args, **kwargs)
示例2: get_menu_items_for_rendering
# 需要导入模块: from wagtail.core import hooks [as 别名]
# 或者: from wagtail.core.hooks import get_hooks [as 别名]
def get_menu_items_for_rendering(self):
"""
Return a list of 'menu items' to be included in the context for
rendering the current level of the menu.
The responsibility for sourcing, priming, and modifying menu items is
split between three methods: ``get_raw_menu_items()``,
``prime_menu_items()`` and ``modify_menu_items()``, respectively.
"""
items = self.get_raw_menu_items()
# Allow hooks to modify the raw list
for hook in hooks.get_hooks('menus_modify_raw_menu_items'):
items = hook(items, **self.common_hook_kwargs)
# Prime and modify the menu items accordingly
items = self.modify_menu_items(self.prime_menu_items(items))
if isinstance(items, GeneratorType):
items = list(items)
# Allow hooks to modify the primed/modified list
hook_methods = hooks.get_hooks('menus_modify_primed_menu_items')
for hook in hook_methods:
items = hook(items, **self.common_hook_kwargs)
return items
示例3: for_frontend
# 需要导入模块: from wagtail.core import hooks [as 别名]
# 或者: from wagtail.core.hooks import get_hooks [as 别名]
def for_frontend(request, page_id):
items = [
EditPageItem(Page.objects.get(id=page_id)),
AddPageItem(Page.objects.get(id=page_id)),
]
for fn in hooks.get_hooks('construct_wagtail_userbar'):
fn(request, items)
# Render the items
rendered_items = [item.render(request) for item in items]
# Remove any unrendered items
rendered_items = [item for item in rendered_items if item]
# Render the edit bird
return TemplateResponse(request, 'wagtailadmin/userbar/base.html', {
'items': rendered_items,
})
示例4: home
# 需要导入模块: from wagtail.core import hooks [as 别名]
# 或者: from wagtail.core.hooks import get_hooks [as 别名]
def home(request):
panels = [
SiteSummaryPanel(request),
UpgradeNotificationPanel(request),
PagesForModerationPanel(request),
LockedPagesPanel(request),
RecentEditsPanel(request),
]
for fn in hooks.get_hooks('construct_homepage_panels'):
fn(request, panels)
site_details = get_site_for_user(request.user)
return TemplateResponse(request, "wagtailadmin/home.html", {
'root_page': site_details['root_page'],
'root_site': site_details['root_site'],
'site_name': site_details['site_name'],
'panels': sorted(panels, key=lambda p: p.order),
'user': request.user
})
示例5: __init__
# 需要导入模块: from wagtail.core import hooks [as 别名]
# 或者: from wagtail.core.hooks import get_hooks [as 别名]
def __init__(self, request, **kwargs):
self.request = request
self.context = kwargs
self.context['user_page_permissions'] = UserPagePermissionsProxy(self.request.user)
self.menu_items = [
menu_item
for menu_item in _get_base_page_action_menu_items()
if menu_item.is_shown(self.request, self.context)
]
self.menu_items.sort(key=lambda item: item.order)
for hook in hooks.get_hooks('construct_page_action_menu'):
hook(self.menu_items, self.request, self.context)
try:
self.default_item = self.menu_items.pop(0)
except IndexError:
self.default_item = None
示例6: render_html
# 需要导入模块: from wagtail.core import hooks [as 别名]
# 或者: from wagtail.core.hooks import get_hooks [as 别名]
def render_html(self, request, current=None):
search_areas = self.search_items_for_request(request)
# Get query parameter
form = SearchForm(request.GET)
query = ''
if form.is_valid():
query = form.cleaned_data['q']
# provide a hook for modifying the search area, if construct_hook_name has been set
if self.construct_hook_name:
for fn in hooks.get_hooks(self.construct_hook_name):
fn(request, search_areas)
rendered_search_areas = []
for item in search_areas:
rendered_search_areas.append(item.render_html(request, query, current))
return mark_safe(''.join(rendered_search_areas))
示例7: create
# 需要导入模块: from wagtail.core import hooks [as 别名]
# 或者: from wagtail.core.hooks import get_hooks [as 别名]
def create(request):
for fn in hooks.get_hooks('before_create_user'):
result = fn(request)
if hasattr(result, 'status_code'):
return result
if request.method == 'POST':
form = get_user_creation_form()(request.POST, request.FILES)
if form.is_valid():
user = form.save()
messages.success(request, _("User '{0}' created.").format(user), buttons=[
messages.button(reverse('wagtailusers_users:edit', args=(user.pk,)), _('Edit'))
])
for fn in hooks.get_hooks('after_create_user'):
result = fn(request, user)
if hasattr(result, 'status_code'):
return result
return redirect('wagtailusers_users:index')
else:
messages.error(request, _("The user could not be created due to errors."))
else:
form = get_user_creation_form()()
return TemplateResponse(request, 'wagtailusers/users/create.html', {
'form': form,
})
示例8: delete
# 需要导入模块: from wagtail.core import hooks [as 别名]
# 或者: from wagtail.core.hooks import get_hooks [as 别名]
def delete(request, user_id):
user = get_object_or_404(User, pk=user_id)
if not user_can_delete_user(request.user, user):
return permission_denied(request)
for fn in hooks.get_hooks('before_delete_user'):
result = fn(request, user)
if hasattr(result, 'status_code'):
return result
if request.method == 'POST':
user.delete()
messages.success(request, _("User '{0}' deleted.").format(user))
for fn in hooks.get_hooks('after_delete_user'):
result = fn(request, user)
if hasattr(result, 'status_code'):
return result
return redirect('wagtailusers_users:index')
return TemplateResponse(request, "wagtailusers/users/confirm_delete.html", {
'user': user,
})
示例9: get_base_page_queryset
# 需要导入模块: from wagtail.core import hooks [as 别名]
# 或者: from wagtail.core.hooks import get_hooks [as 别名]
def get_base_page_queryset(self):
qs = Page.objects.filter(live=True, expired=False, show_in_menus=True)
# allow hooks to modify the queryset
for hook in hooks.get_hooks('menus_modify_base_page_queryset'):
qs = hook(qs, **self.common_hook_kwargs)
return qs
示例10: get_base_menuitem_queryset
# 需要导入模块: from wagtail.core import hooks [as 别名]
# 或者: from wagtail.core.hooks import get_hooks [as 别名]
def get_base_menuitem_queryset(self):
qs = self.get_menu_items_manager().for_display()
# Prefetch minimal page values only. The rest will be
# fetched by get_pages_for_display()
qs = qs.select_related('link_page').defer(*[
'link_page__{}'.format(f.name) for f in Page._meta.get_fields()
if f.concrete and f.name not in ('id', 'path', 'depth')
])
# allow hooks to modify the queryset
for hook in hooks.get_hooks('menus_modify_base_menuitem_queryset'):
qs = hook(qs, **self.common_hook_kwargs)
return qs
示例11: populate
# 需要导入模块: from wagtail.core import hooks [as 别名]
# 或者: from wagtail.core.hooks import get_hooks [as 别名]
def populate(self):
for fn in hooks.get_hooks('register_admin_viewset'):
viewset = fn()
self.register(viewset)
示例12: registered_menu_items
# 需要导入模块: from wagtail.core import hooks [as 别名]
# 或者: from wagtail.core.hooks import get_hooks [as 别名]
def registered_menu_items(self):
if self._registered_menu_items is None:
self._registered_menu_items = [fn() for fn in hooks.get_hooks(self.register_hook_name)]
return self._registered_menu_items
示例13: render_html
# 需要导入模块: from wagtail.core import hooks [as 别名]
# 或者: from wagtail.core.hooks import get_hooks [as 别名]
def render_html(self, request):
menu_items = self.menu_items_for_request(request)
# provide a hook for modifying the menu, if construct_hook_name has been set
if self.construct_hook_name:
for fn in hooks.get_hooks(self.construct_hook_name):
fn(request, menu_items)
rendered_menu_items = []
for item in sorted(menu_items, key=lambda i: i.order):
rendered_menu_items.append(item.render_html(request))
return mark_safe(''.join(rendered_menu_items))
示例14: search
# 需要导入模块: from wagtail.core import hooks [as 别名]
# 或者: from wagtail.core.hooks import get_hooks [as 别名]
def search(request, parent_page_id=None):
# A missing or empty page_type parameter indicates 'all page types' (i.e. descendants of wagtailcore.page)
page_type_string = request.GET.get('page_type') or 'wagtailcore.page'
try:
desired_classes = page_models_from_string(page_type_string)
except (ValueError, LookupError):
raise Http404
pages = Page.objects.all()
# allow hooks to modify the queryset
for hook in hooks.get_hooks('construct_page_chooser_queryset'):
pages = hook(pages, request)
search_form = SearchForm(request.GET)
if search_form.is_valid() and search_form.cleaned_data['q']:
pages = pages.exclude(
depth=1 # never include root
)
pages = filter_page_type(pages, desired_classes)
pages = pages.specific()
pages = pages.search(search_form.cleaned_data['q'])
else:
pages = pages.none()
paginator = Paginator(pages, per_page=25)
pages = paginator.get_page(request.GET.get('p'))
for page in pages:
page.can_choose = True
return TemplateResponse(
request, 'wagtailadmin/chooser/_search_results.html',
shared_context(request, {
'searchform': search_form,
'pages': pages,
'page_type_string': page_type_string,
})
)
示例15: get_collection_contents
# 需要导入模块: from wagtail.core import hooks [as 别名]
# 或者: from wagtail.core.hooks import get_hooks [as 别名]
def get_collection_contents(self):
collection_contents = [
hook(self.object)
for hook in hooks.get_hooks('describe_collection_contents')
]
# filter out any hook responses that report that the collection is empty
# (by returning None, or a dict with 'count': 0)
def is_nonempty(item_type):
return item_type and item_type['count'] > 0
return list(filter(is_nonempty, collection_contents))