本文整理汇总了Python中wagtail.core.hooks.get_hooks函数的典型用法代码示例。如果您正苦于以下问题:Python get_hooks函数的具体用法?Python get_hooks怎么用?Python get_hooks使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_hooks函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: edit
def edit(request, user_id):
user = get_object_or_404(User, pk=user_id)
can_delete = user_can_delete_user(request.user, user)
editing_self = request.user == user
for fn in hooks.get_hooks('before_edit_user'):
result = fn(request, user)
if hasattr(result, 'status_code'):
return result
if request.method == 'POST':
form = get_user_edit_form()(request.POST, request.FILES, instance=user, editing_self=editing_self)
if form.is_valid():
user = form.save()
messages.success(request, _("User '{0}' updated.").format(user), buttons=[
messages.button(reverse('wagtailusers_users:edit', args=(user.pk,)), _('Edit'))
])
for fn in hooks.get_hooks('after_edit_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 saved due to errors."))
else:
form = get_user_edit_form()(instance=user, editing_self=editing_self)
return render(request, 'wagtailusers/users/edit.html', {
'user': user,
'form': form,
'can_delete': can_delete,
})
开发者ID:morris-tech,项目名称:wagtail,代码行数:31,代码来源:users.py
示例2: edit
def edit(request, user_id):
user = get_object_or_404(User, pk=user_id)
can_delete = user_can_delete_user(request.user, user)
editing_self = request.user == user
for fn in hooks.get_hooks('before_edit_user'):
result = fn(request, user)
if hasattr(result, 'status_code'):
return result
if request.method == 'POST':
form = get_user_edit_form()(request.POST, request.FILES, instance=user, editing_self=editing_self)
if form.is_valid():
user = form.save()
messages.success(request, _("Your details have been updated. You've been logged out for security reasons, "
"please login to continue."))
for fn in hooks.get_hooks('after_edit_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 saved due to errors."))
else:
form = get_user_edit_form()(instance=user, editing_self=editing_self)
return render(request, 'wagtailusers/users/edit.html', {
'user': user,
'form': form,
'can_delete': can_delete,
})
开发者ID:Henk-JanVanHasselaar,项目名称:wagtail,代码行数:30,代码来源:users.py
示例3: create
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 render(request, 'wagtailusers/users/create.html', {
'form': form,
})
开发者ID:morris-tech,项目名称:wagtail,代码行数:25,代码来源:users.py
示例4: delete
def delete(request, page_id):
page = get_object_or_404(Page, id=page_id).specific
if not page.permissions_for_user(request.user).can_delete():
raise PermissionDenied
with transaction.atomic():
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:hellomrjack,项目名称:wagtail,代码行数:33,代码来源:pages.py
示例5: 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:BertrandBordage,项目名称:wagtail,代码行数:29,代码来源:home.py
示例6: test_after_hook
def test_after_hook(self):
def after_hook():
pass
with self.register_hook('test_hook_name', after_hook, order=1):
hook_fns = hooks.get_hooks('test_hook_name')
self.assertEqual(hook_fns, [test_hook, after_hook])
开发者ID:morris-tech,项目名称:wagtail,代码行数:7,代码来源:test_hooks.py
示例7: test_before_hook
def test_before_hook(self):
def before_hook():
pass
with self.register_hook('test_hook_name', before_hook, order=-1):
hook_fns = hooks.get_hooks('test_hook_name')
self.assertEqual(hook_fns, [before_hook, test_hook])
开发者ID:morris-tech,项目名称:wagtail,代码行数:7,代码来源:test_hooks.py
示例8: chooser
def chooser(request):
Image = get_image_model()
if permission_policy.user_has_permission(request.user, 'add'):
ImageForm = get_image_form(Image)
uploadform = ImageForm(user=request.user)
else:
uploadform = None
images = Image.objects.order_by('-created_at')
# allow hooks to modify the queryset
for hook in hooks.get_hooks('construct_image_chooser_queryset'):
images = hook(images, request)
if (
'q' in request.GET or 'p' in request.GET or 'tag' in request.GET or
'collection_id' in request.GET
):
# this request is triggered from search, pagination or 'popular tags';
# we will just render the results.html fragment
collection_id = request.GET.get('collection_id')
if collection_id:
images = images.filter(collection=collection_id)
searchform = SearchForm(request.GET)
if searchform.is_valid():
q = searchform.cleaned_data['q']
images = images.search(q)
is_searching = True
else:
is_searching = False
q = None
tag_name = request.GET.get('tag')
if tag_name:
images = images.filter(tags__name=tag_name)
# Pagination
paginator, images = paginate(request, images, per_page=12)
return render(request, "wagtailimages/chooser/results.html", {
'images': images,
'is_searching': is_searching,
'query_string': q,
'will_select_format': request.GET.get('select_format')
})
else:
paginator, images = paginate(request, images, per_page=12)
context = get_chooser_context(request)
context.update({
'images': images,
'uploadform': uploadform,
})
return render_modal_workflow(
request, 'wagtailimages/chooser/chooser.html', None, context,
json_data=get_chooser_js_data()
)
开发者ID:coredumperror,项目名称:wagtail,代码行数:60,代码来源:chooser.py
示例9: chooser_upload
def chooser_upload(request):
Image = get_image_model()
ImageForm = get_image_form(Image)
if request.method == 'POST':
image = Image(uploaded_by_user=request.user)
form = ImageForm(
request.POST, request.FILES, instance=image, user=request.user, prefix='image-chooser-upload'
)
if form.is_valid():
# Set image file size
image.file_size = image.file.size
# Set image file hash
image.file.seek(0)
image._set_file_hash(image.file.read())
image.file.seek(0)
form.save()
# Reindex the image to make sure all tags are indexed
search_index.insert_or_update_object(image)
if request.GET.get('select_format'):
form = ImageInsertionForm(
initial={'alt_text': image.default_alt_text}, prefix='image-chooser-insertion'
)
return render_modal_workflow(
request, 'wagtailimages/chooser/select_format.html', None,
{'image': image, 'form': form}, json_data={'step': 'select_format'}
)
else:
# not specifying a format; return the image details now
return render_modal_workflow(
request, None, None,
None, json_data={'step': 'image_chosen', 'result': get_image_result_data(image)}
)
else:
form = ImageForm(user=request.user, prefix='image-chooser-upload')
images = Image.objects.order_by('-created_at')
# allow hooks to modify the queryset
for hook in hooks.get_hooks('construct_image_chooser_queryset'):
images = hook(images, request)
paginator = Paginator(images, per_page=12)
images = paginator.get_page(request.GET.get('p'))
context = get_chooser_context(request)
context.update({
'images': images,
'uploadform': form,
})
return render_modal_workflow(
request, 'wagtailimages/chooser/chooser.html', None, context,
json_data=get_chooser_js_data()
)
开发者ID:nealtodd,项目名称:wagtail,代码行数:59,代码来源:chooser.py
示例10: 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:BertrandBordage,项目名称:wagtail,代码行数:8,代码来源:groups.py
示例11: 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:Henk-JanVanHasselaar,项目名称:wagtail,代码行数:8,代码来源:test_admin.py
示例12: 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,
'uploadid': uuid.uuid4(),
})
开发者ID:sprymix,项目名称:wagtail,代码行数:58,代码来源:chooser.py
示例13: _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:Henk-JanVanHasselaar,项目名称:wagtail,代码行数:9,代码来源:models.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 mark_safe(''.join(snippets))
开发者ID:springload,项目名称:wagtail,代码行数:9,代码来源:wagtailadmin_tags.py
示例15: serve
def serve(request, document_id, document_filename):
Document = get_document_model()
doc = get_object_or_404(Document, id=document_id)
# We want to ensure that the document filename provided in the URL matches the one associated with the considered
# document_id. If not we can't be sure that the document the user wants to access is the one corresponding to the
# <document_id, document_filename> pair.
if doc.filename != document_filename:
raise Http404('This document does not match the given filename.')
for fn in hooks.get_hooks('before_serve_document'):
result = fn(doc, request)
if isinstance(result, HttpResponse):
return result
# Send document_served signal
document_served.send(sender=Document, instance=doc, request=request)
try:
local_path = doc.file.path
except NotImplementedError:
local_path = None
if local_path:
# Use wagtail.utils.sendfile to serve the file;
# this provides support for mimetypes, if-modified-since and django-sendfile backends
if hasattr(settings, 'SENDFILE_BACKEND'):
return sendfile(request, local_path, attachment=True, attachment_filename=doc.filename)
else:
# Fallback to streaming backend if user hasn't specified SENDFILE_BACKEND
return sendfile(
request,
local_path,
attachment=True,
attachment_filename=doc.filename,
backend=sendfile_streaming_backend.sendfile
)
else:
# We are using a storage backend which does not expose filesystem paths
# (e.g. storages.backends.s3boto.S3BotoStorage).
# Fall back on pre-sendfile behaviour of reading the file content and serving it
# as a StreamingHttpResponse
wrapper = FileWrapper(doc.file)
response = StreamingHttpResponse(wrapper, content_type='application/octet-stream')
response['Content-Disposition'] = 'attachment; filename=%s' % doc.filename
# FIXME: storage backends are not guaranteed to implement 'size'
response['Content-Length'] = doc.file.size
return response
开发者ID:morris-tech,项目名称:wagtail,代码行数:56,代码来源:serve.py
示例16: filter_queryset
def filter_queryset(self, request, queryset, view):
if request.GET.get('for_explorer'):
if not hasattr(queryset, '_filtered_by_child_of'):
raise BadRequestError("filtering by for_explorer without child_of is not supported")
parent_page = queryset._filtered_by_child_of
for hook in hooks.get_hooks('construct_explorer_page_queryset'):
queryset = hook(parent_page, queryset, request)
return queryset
开发者ID:BertrandBordage,项目名称:wagtail,代码行数:10,代码来源:filters.py
示例17: account
def account(request):
items = []
for fn in hooks.get_hooks('register_account_menu_item'):
item = fn(request)
if item:
items.append(item)
return render(request, 'wagtailadmin/account/account.html', {
'items': items,
})
开发者ID:springload,项目名称:wagtail,代码行数:11,代码来源:account.py
示例18: get_forms_for_user
def get_forms_for_user(user):
"""
Return a queryset of form pages that this user is allowed to access the submissions for
"""
editable_forms = UserPagePermissionsProxy(user).editable_pages()
editable_forms = editable_forms.filter(content_type__in=get_form_types())
# Apply hooks
for fn in hooks.get_hooks('filter_form_submissions_for_user'):
editable_forms = fn(user, editable_forms)
return editable_forms
开发者ID:BertrandBordage,项目名称:wagtail,代码行数:12,代码来源:utils.py
示例19: get_collection_contents
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:BertrandBordage,项目名称:wagtail,代码行数:12,代码来源:collections.py
示例20: render_html
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:Proper-Job,项目名称:wagtail,代码行数:13,代码来源:menu.py
注:本文中的wagtail.core.hooks.get_hooks函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论