本文整理汇总了Python中wagtail.wagtailcore.hooks.get_hooks函数的典型用法代码示例。如果您正苦于以下问题:Python get_hooks函数的具体用法?Python get_hooks怎么用?Python get_hooks使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_hooks函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: delete
def delete(request, page_id):
page = get_object_or_404(Page, id=page_id)
if not page.permissions_for_user(request.user).can_delete():
raise PermissionDenied
for fn in hooks.get_hooks("before_delete_page"):
result = fn(request, page)
if hasattr(result, "status_code"):
return result
next_url = get_valid_next_url_from_request(request)
if request.method == "POST":
parent_id = page.get_parent().id
page.delete()
messages.success(request, _("Page '{0}' deleted.").format(page.get_admin_display_title()))
for fn in hooks.get_hooks("after_delete_page"):
result = fn(request, page)
if hasattr(result, "status_code"):
return result
if next_url:
return redirect(next_url)
return redirect("wagtailadmin_explore", parent_id)
return render(
request,
"wagtailadmin/pages/confirm_delete.html",
{"page": page, "descendant_count": page.get_descendant_count(), "next": next_url},
)
开发者ID:mvantellingen,项目名称:wagtail,代码行数:32,代码来源:pages.py
示例2: delete
def delete(request, page_id):
page = get_object_or_404(Page, id=page_id)
if not page.permissions_for_user(request.user).can_delete():
raise PermissionDenied
for fn in hooks.get_hooks('before_delete_page'):
result = fn(request, page)
if hasattr(result, 'status_code'):
return result
next_url = get_valid_next_url_from_request(request)
if request.method == 'POST':
parent_id = page.get_parent().id
page.delete()
messages.success(request, _("Page '{0}' deleted.").format(page.title))
for fn in hooks.get_hooks('after_delete_page'):
result = fn(request, page)
if hasattr(result, 'status_code'):
return result
if next_url:
return redirect(next_url)
return redirect('wagtailadmin_explore', parent_id)
return render(request, 'wagtailadmin/pages/confirm_delete.html', {
'page': page,
'descendant_count': page.get_descendant_count(),
'next': next_url,
})
开发者ID:jaydensmith,项目名称:wagtail,代码行数:32,代码来源:pages.py
示例3: register_hook
def register_hook(self, hook_name, fn):
from wagtail.wagtailcore import hooks
hooks.register(hook_name, fn)
try:
yield
finally:
hooks.get_hooks(hook_name).remove(fn)
开发者ID:chrxr,项目名称:wagtail,代码行数:8,代码来源:utils.py
示例4: home
def home(request):
panels = [
SiteSummaryPanel(request),
UpgradeNotificationPanel(request),
PagesForModerationPanel(request),
RecentEditsPanel(request),
]
for fn in hooks.get_hooks('construct_homepage_panels'):
fn(request, panels)
root_page = get_explorable_root_page(request.user)
if root_page:
root_site = root_page.get_site()
else:
root_site = None
real_site_name = None
if root_site:
real_site_name = root_site.site_name if root_site.site_name else root_site.hostname
return render(request, "wagtailadmin/home.html", {
'root_page': root_page,
'root_site': root_site,
'site_name': real_site_name if real_site_name else settings.WAGTAIL_SITE_NAME,
'panels': sorted(panels, key=lambda p: p.order),
'user': request.user
})
开发者ID:thenewguy,项目名称:wagtail,代码行数:29,代码来源:home.py
示例5: setUp
def setUp(self):
# Create a group to edit
self.test_group = Group.objects.create(name='test group')
self.root_page = Page.objects.get(id=1)
self.root_add_permission = GroupPagePermission.objects.create(page=self.root_page,
permission_type='add',
group=self.test_group)
self.home_page = Page.objects.get(id=2)
# Get the hook-registered permissions, and add one to this group
self.registered_permissions = Permission.objects.none()
for fn in hooks.get_hooks('register_permissions'):
self.registered_permissions = self.registered_permissions | fn()
self.existing_permission = self.registered_permissions.order_by('pk')[0]
self.another_permission = self.registered_permissions.order_by('pk')[1]
self.test_group.permissions.add(self.existing_permission)
# set up collections to test document permissions
self.root_collection = Collection.get_first_root_node()
self.evil_plans_collection = self.root_collection.add_child(name="Evil plans")
self.add_doc_permission = Permission.objects.get(
content_type__app_label='wagtaildocs', codename='add_document'
)
self.change_doc_permission = Permission.objects.get(
content_type__app_label='wagtaildocs', codename='change_document'
)
GroupCollectionPermission.objects.create(
group=self.test_group,
collection=self.evil_plans_collection,
permission=self.add_doc_permission,
)
# Login
self.login()
开发者ID:jschneier,项目名称:wagtail,代码行数:35,代码来源:tests.py
示例6: delete
def delete(request, page_id):
page = get_object_or_404(Page, id=page_id)
if not page.permissions_for_user(request.user).can_delete():
raise PermissionDenied
if request.POST:
if page.live:
# fetch params to pass to the page_unpublished_signal, before the
# deletion happens
specific_class = page.specific_class
specific_page = page.specific
parent_id = page.get_parent().id
page.delete()
# If the page is live, send the unpublished signal
if page.live:
page_unpublished.send(sender=specific_class, instance=specific_page)
messages.success(request, _("Page '{0}' deleted.").format(page.title))
for fn in hooks.get_hooks('after_delete_page'):
result = fn(request, page)
if hasattr(result, 'status_code'):
return result
return redirect('wagtailadmin_explore', parent_id)
return render(request, 'wagtailadmin/pages/confirm_delete.html', {
'page': page,
'descendant_count': page.get_descendant_count()
})
开发者ID:Rakuli,项目名称:wagtail,代码行数:32,代码来源:pages.py
示例7: test_after_hook
def test_after_hook(self):
def after_hook():
self
with self.register_hook('test_hook_name', after_hook):
hook_fns = hooks.get_hooks('test_hook_name')
self.assertEqual(hook_fns, [test_hook, after_hook])
开发者ID:CenterForOpenScience,项目名称:centerforopenscience.org,代码行数:7,代码来源:test_wagtail_hooks.py
示例8: test_before_hook
def test_before_hook(self):
def before_hook():
pass
with self.register_hook('test_hook_name', before_hook):
hook_fns = hooks.get_hooks('test_hook_name')
self.assertEqual(hook_fns, [test_hook, before_hook])
开发者ID:CenterForOpenScience,项目名称:centerforopenscience.org,代码行数:7,代码来源:test_wagtail_hooks.py
示例9: wagtailuserbar
def wagtailuserbar(context, position='bottom-right'):
# Find request object
try:
request = context['request']
except KeyError:
return ''
# Don't render if user doesn't have permission to access the admin area
if not request.user.has_perm('wagtailadmin.access_admin'):
return ''
# Only render if the context contains a variable referencing a saved page
page = get_page_instance(context)
if page is None:
return ''
# Dont render anything if the page has not been saved - i.e. a preview
if page.pk is None:
return ''
try:
revision_id = request.revision_id
except AttributeError:
revision_id = None
if revision_id is None:
items = [
AdminItem(),
ExplorePageItem(Page.objects.get(id=page.id)),
EditPageItem(Page.objects.get(id=page.id)),
AddPageItem(Page.objects.get(id=page.id)),
]
else:
items = [
AdminItem(),
ExplorePageItem(PageRevision.objects.get(id=revision_id).page),
EditPageItem(PageRevision.objects.get(id=revision_id).page),
AddPageItem(PageRevision.objects.get(id=revision_id).page),
ApproveModerationEditPageItem(PageRevision.objects.get(id=revision_id)),
RejectModerationEditPageItem(PageRevision.objects.get(id=revision_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 userbar items
return render_to_string('wagtailadmin/userbar/base.html', {
'request': request,
'items': rendered_items,
'position': position,
'page': page,
'revision_id': revision_id
})
开发者ID:DimiC,项目名称:wagtail,代码行数:59,代码来源:wagtailuserbar.py
示例10: run_deprecated_edit_bird_hook
def run_deprecated_edit_bird_hook(request, items):
for fn in hooks.get_hooks('construct_wagtail_edit_bird'):
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__), RemovedInWagtail12Warning
)
开发者ID:bjesus,项目名称:wagtail,代码行数:8,代码来源:userbar.py
示例11: get_permission_panel_classes
def get_permission_panel_classes():
global _permission_panel_classes
if _permission_panel_classes is None:
_permission_panel_classes = [GroupPagePermissionFormSet]
for fn in hooks.get_hooks('register_group_permission_panel'):
_permission_panel_classes.append(fn())
return _permission_panel_classes
开发者ID:Anlim,项目名称:wagtail,代码行数:8,代码来源:groups.py
示例12: clean
def clean(cls, html):
if not cls.has_loaded_custom_whitelist_rules:
for fn in hooks.get_hooks('construct_whitelister_element_rules'):
cls.element_rules = cls.element_rules.copy()
cls.element_rules.update(fn())
cls.has_loaded_custom_whitelist_rules = True
return super(DbWhitelister, cls).clean(html)
开发者ID:Eraldo,项目名称:wagtail,代码行数:8,代码来源:rich_text.py
示例13: test_registered_permission
def test_registered_permission(self):
permission = Permission.objects.get_by_natural_key(
app_label='tests', model='testsetting', codename='change_testsetting')
for fn in hooks.get_hooks('register_permissions'):
if permission in fn():
break
else:
self.fail('Change permission for tests.TestSetting not registered')
开发者ID:DimiC,项目名称:wagtail,代码行数:8,代码来源:test_admin.py
示例14: hook_output
def hook_output(hook_name):
"""
Example: {% hook_output 'insert_editor_css' %}
Whenever we have a hook whose functions take no parameters and return a string, this tag can be used
to output the concatenation of all of those return values onto the page.
Note that the output is not escaped - it is the hook function's responsibility to escape unsafe content.
"""
snippets = [fn() for fn in hooks.get_hooks(hook_name)]
return "".join(snippets)
开发者ID:niceguydave,项目名称:wagtail,代码行数:9,代码来源:wagtailadmin_tags.py
示例15: chooser
def chooser(request):
Document = get_document_model()
if permission_policy.user_has_permission(request.user, 'add'):
DocumentForm = get_document_form(Document)
uploadform = DocumentForm(user=request.user)
else:
uploadform = None
documents = Document.objects.all()
# allow hooks to modify the queryset
for hook in hooks.get_hooks('construct_document_chooser_queryset'):
documents = hook(documents, request)
q = None
if 'q' in request.GET or 'p' in request.GET or 'collection_id' in request.GET:
collection_id = request.GET.get('collection_id')
if collection_id:
documents = documents.filter(collection=collection_id)
searchform = SearchForm(request.GET)
if searchform.is_valid():
q = searchform.cleaned_data['q']
documents = documents.search(q)
is_searching = True
else:
documents = documents.order_by('-created_at')
is_searching = False
# Pagination
paginator, documents = paginate(request, documents, per_page=10)
return render(request, "wagtaildocs/chooser/results.html", {
'documents': documents,
'query_string': q,
'is_searching': is_searching,
})
else:
searchform = SearchForm()
collections = Collection.objects.all()
if len(collections) < 2:
collections = None
documents = documents.order_by('-created_at')
paginator, documents = paginate(request, documents, per_page=10)
return render_modal_workflow(request, 'wagtaildocs/chooser/chooser.html', 'wagtaildocs/chooser/chooser.js', {
'documents': documents,
'uploadform': uploadform,
'searchform': searchform,
'collections': collections,
'is_searching': False,
})
开发者ID:kapito,项目名称:wagtail,代码行数:57,代码来源:chooser.py
示例16: get_collection_contents
def get_collection_contents(self):
collection_contents = [hook(self.instance) 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:quru,项目名称:wagtail,代码行数:9,代码来源:collections.py
示例17: _search_for_operations
def _search_for_operations(cls):
if cls._registered_operations is not None:
return
operations = []
for fn in hooks.get_hooks('register_image_operations'):
operations.extend(fn())
cls._registered_operations = dict(operations)
开发者ID:tony,项目名称:wagtail,代码行数:9,代码来源:models.py
示例18: test_registered_permission
def test_registered_permission(self):
permission = Permission.objects.get_by_natural_key(
app_label="tests", model="testsetting", codename="change_testsetting"
)
for fn in hooks.get_hooks("register_permissions"):
if permission in fn():
break
else:
self.fail("Change permission for tests.TestSetting not registered")
开发者ID:jschneier,项目名称:wagtail,代码行数:9,代码来源:test_admin.py
示例19: get
def get(self, request, *args, **kwargs):
if not request.site:
raise Http404
path_components = list(operator.itemgetter(0, -1)(request.path.strip('/').split('/')))
page, args, kwargs = request.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:fun-alex-alex2006hw,项目名称:puput,代码行数:11,代码来源:views.py
示例20: get_link_handler
def get_link_handler(link_type):
global LINK_HANDLERS, has_loaded_link_handlers
if not has_loaded_link_handlers:
for hook in hooks.get_hooks('register_rich_text_link_handler'):
handler_name, handler = hook()
LINK_HANDLERS[handler_name] = handler
has_loaded_link_handlers = True
return LINK_HANDLERS[link_type]
开发者ID:Eraldo,项目名称:wagtail,代码行数:11,代码来源:rich_text.py
注:本文中的wagtail.wagtailcore.hooks.get_hooks函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论