當前位置: 首頁>>代碼示例>>Python>>正文


Python hooks.get_hooks方法代碼示例

本文整理匯總了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) 
開發者ID:APSL,項目名稱:puput,代碼行數:27,代碼來源:views.py

示例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 
開發者ID:rkhleics,項目名稱:wagtailmenus,代碼行數:27,代碼來源:menus.py

示例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,
    }) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:21,代碼來源:userbar.py

示例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
    }) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:24,代碼來源:home.py

示例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 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:22,代碼來源:action_menu.py

示例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)) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:21,代碼來源:search.py

示例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,
    }) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:27,代碼來源:users.py

示例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,
    }) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:24,代碼來源:users.py

示例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 
開發者ID:rkhleics,項目名稱:wagtailmenus,代碼行數:8,代碼來源:menus.py

示例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 
開發者ID:rkhleics,項目名稱:wagtailmenus,代碼行數:16,代碼來源:menus.py

示例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) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:6,代碼來源:__init__.py

示例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 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:6,代碼來源:menu.py

示例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)) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:14,代碼來源:menu.py

示例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,
        })
    ) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:41,代碼來源:chooser.py

示例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)) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:14,代碼來源:collections.py


注:本文中的wagtail.core.hooks.get_hooks方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。