本文整理汇总了Python中wagtail.admin.messages.error方法的典型用法代码示例。如果您正苦于以下问题:Python messages.error方法的具体用法?Python messages.error怎么用?Python messages.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wagtail.admin.messages
的用法示例。
在下文中一共展示了messages.error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: approve_moderation
# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import error [as 别名]
def approve_moderation(request, revision_id):
revision = get_object_or_404(PageRevision, id=revision_id)
if not revision.page.permissions_for_user(request.user).can_publish():
raise PermissionDenied
if not revision.submitted_for_moderation:
messages.error(request, _("The page '{0}' is not currently awaiting moderation.").format(revision.page.get_admin_display_title()))
return redirect('wagtailadmin_home')
if request.method == 'POST':
revision.approve_moderation()
message = _("Page '{0}' published.").format(revision.page.get_admin_display_title())
buttons = []
if revision.page.url is not None:
buttons.append(messages.button(revision.page.url, _('View live'), new_window=True))
buttons.append(messages.button(reverse('wagtailadmin_pages:edit', args=(revision.page.id,)), _('Edit')))
messages.success(request, message, buttons=buttons)
if not send_notification(revision.id, 'approved', request.user.pk):
messages.error(request, _("Failed to send approval notifications"))
return redirect('wagtailadmin_home')
示例2: reject_moderation
# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import error [as 别名]
def reject_moderation(request, revision_id):
revision = get_object_or_404(PageRevision, id=revision_id)
if not revision.page.permissions_for_user(request.user).can_publish():
raise PermissionDenied
if not revision.submitted_for_moderation:
messages.error(request, _("The page '{0}' is not currently awaiting moderation.").format(revision.page.get_admin_display_title()))
return redirect('wagtailadmin_home')
if request.method == 'POST':
revision.reject_moderation()
messages.success(request, _("Page '{0}' rejected for publication.").format(revision.page.get_admin_display_title()), buttons=[
messages.button(reverse('wagtailadmin_pages:edit', args=(revision.page.id,)), _('Edit'))
])
if not send_notification(revision.id, 'rejected', request.user.pk):
messages.error(request, _("Failed to send rejection notifications"))
return redirect('wagtailadmin_home')
示例3: create
# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import error [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,
})
示例4: add
# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import error [as 别名]
def add(request):
if request.method == 'POST':
form = RedirectForm(request.POST, request.FILES)
if form.is_valid():
theredirect = form.save()
messages.success(request, _("Redirect '{0}' added.").format(theredirect.title), buttons=[
messages.button(reverse('wagtailredirects:edit', args=(theredirect.id,)), _('Edit'))
])
return redirect('wagtailredirects:index')
else:
messages.error(request, _("The redirect could not be created due to errors."))
else:
form = RedirectForm()
return TemplateResponse(request, "wagtailredirects/add.html", {
'form': form,
})
示例5: form_invalid
# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import error [as 别名]
def form_invalid(self, form):
self.form = form
error_message = self.get_error_message()
if error_message is not None:
messages.error(self.request, error_message)
return super().form_invalid(form)
示例6: move_confirm
# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import error [as 别名]
def move_confirm(request, page_to_move_id, destination_id):
page_to_move = get_object_or_404(Page, id=page_to_move_id).specific
destination = get_object_or_404(Page, id=destination_id)
if not page_to_move.permissions_for_user(request.user).can_move_to(destination):
raise PermissionDenied
if not Page._slug_is_available(page_to_move.slug, destination, page=page_to_move):
messages.error(
request,
_("The slug '{0}' is already in use at the selected parent page. Make sure the slug is unique and try again".format(page_to_move.slug))
)
return redirect('wagtailadmin_pages:move_choose_destination', page_to_move.id, destination.id)
for fn in hooks.get_hooks('before_move_page'):
result = fn(request, page_to_move, destination)
if hasattr(result, 'status_code'):
return result
if request.method == 'POST':
# any invalid moves *should* be caught by the permission check above,
# so don't bother to catch InvalidMoveToDescendant
page_to_move.move(destination, pos='last-child')
messages.success(request, _("Page '{0}' moved.").format(page_to_move.get_admin_display_title()), buttons=[
messages.button(reverse('wagtailadmin_pages:edit', args=(page_to_move.id,)), _('Edit'))
])
for fn in hooks.get_hooks('after_move_page'):
result = fn(request, page_to_move)
if hasattr(result, 'status_code'):
return result
return redirect('wagtailadmin_explore', destination.id)
return TemplateResponse(request, 'wagtailadmin/pages/confirm_move.html', {
'page_to_move': page_to_move,
'destination': destination,
})
示例7: permission_denied
# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import error [as 别名]
def permission_denied(request):
"""Return a standard 'permission denied' response"""
if request.is_ajax():
raise PermissionDenied
from wagtail.admin import messages
messages.error(request, _('Sorry, you do not have permission to access this area.'))
return redirect('wagtailadmin_home')
示例8: generate_url
# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import error [as 别名]
def generate_url(request, image_id, filter_spec):
# Get the image
Image = get_image_model()
try:
image = Image.objects.get(id=image_id)
except Image.DoesNotExist:
return JsonResponse({
'error': "Cannot find image."
}, status=404)
# Check if this user has edit permission on this image
if not permission_policy.user_has_permission_for_instance(request.user, 'change', image):
return JsonResponse({
'error': "You do not have permission to generate a URL for this image."
}, status=403)
# Parse the filter spec to make sure its valid
try:
Filter(spec=filter_spec).operations
except InvalidFilterSpecError:
return JsonResponse({
'error': "Invalid filter spec."
}, status=400)
# Generate url
signature = generate_signature(image_id, filter_spec)
url = reverse('wagtailimages_serve', args=(signature, image_id, filter_spec))
# Get site root url
try:
site_root_url = Site.objects.get(is_default_site=True).root_url
except Site.DoesNotExist:
site_root_url = Site.objects.first().root_url
# Generate preview url
preview_url = reverse('wagtailimages:preview', args=(image_id, filter_spec))
return JsonResponse({'url': site_root_url + url, 'preview_url': preview_url}, status=200)
示例9: add
# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import error [as 别名]
def add(request):
ImageModel = get_image_model()
ImageForm = get_image_form(ImageModel)
if request.method == 'POST':
image = ImageModel(uploaded_by_user=request.user)
form = ImageForm(request.POST, request.FILES, instance=image, user=request.user)
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)
messages.success(request, _("Image '{0}' added.").format(image.title), buttons=[
messages.button(reverse('wagtailimages:edit', args=(image.id,)), _('Edit'))
])
return redirect('wagtailimages:index')
else:
messages.error(request, _("The image could not be created due to errors."))
else:
form = ImageForm(user=request.user)
return TemplateResponse(request, "wagtailimages/images/add.html", {
'form': form,
})
示例10: add
# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import error [as 别名]
def add(request):
Document = get_document_model()
DocumentForm = get_document_form(Document)
if request.method == 'POST':
doc = Document(uploaded_by_user=request.user)
form = DocumentForm(request.POST, request.FILES, instance=doc, user=request.user)
if form.is_valid():
doc.file_size = doc.file.size
# Set new document file hash
doc.file.seek(0)
doc._set_file_hash(doc.file.read())
doc.file.seek(0)
form.save()
# Reindex the document to make sure all tags are indexed
search_index.insert_or_update_object(doc)
messages.success(request, _("Document '{0}' added.").format(doc.title), buttons=[
messages.button(reverse('wagtaildocs:edit', args=(doc.id,)), _('Edit'))
])
return redirect('wagtaildocs:index')
else:
messages.error(request, _("The document could not be saved due to errors."))
else:
form = DocumentForm(user=request.user)
return TemplateResponse(request, "wagtaildocs/documents/add.html", {
'form': form,
})
示例11: edit
# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import error [as 别名]
def edit(request, redirect_id):
theredirect = get_object_or_404(models.Redirect, id=redirect_id)
if not permission_policy.user_has_permission_for_instance(
request.user, 'change', theredirect
):
return permission_denied(request)
if request.method == 'POST':
form = RedirectForm(request.POST, request.FILES, instance=theredirect)
if form.is_valid():
form.save()
messages.success(request, _("Redirect '{0}' updated.").format(theredirect.title), buttons=[
messages.button(reverse('wagtailredirects:edit', args=(theredirect.id,)), _('Edit'))
])
return redirect('wagtailredirects:index')
else:
messages.error(request, _("The redirect could not be saved due to errors."))
else:
form = RedirectForm(instance=theredirect)
return TemplateResponse(request, "wagtailredirects/edit.html", {
'redirect': theredirect,
'form': form,
'user_can_delete': permission_policy.user_has_permission(request.user, 'delete'),
})
示例12: create_redirects_from_dataset
# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import error [as 别名]
def create_redirects_from_dataset(dataset, config):
errors = []
successes = 0
total = 0
for row in dataset:
total += 1
from_link = row[config["from_index"]]
to_link = row[config["to_index"]]
data = {
"old_path": from_link,
"redirect_link": to_link,
"is_permanent": config["permanent"],
}
if config["site"]:
data["site"] = config["site"].pk
form = RedirectForm(data)
if not form.is_valid():
error = to_readable_errors(form.errors.as_text())
errors.append([from_link, to_link, error])
continue
form.save()
successes += 1
return {
"errors": errors,
"errors_count": len(errors),
"successes": successes,
"total": total,
}
示例13: to_readable_errors
# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import error [as 别名]
def to_readable_errors(error):
errors = error.split("\n")
errors = errors[1::2]
errors = [x.lstrip('* ') for x in errors]
errors = ", ".join(errors)
return errors
示例14: add
# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import error [as 别名]
def add(request):
if request.method == 'POST':
# Get query
query_form = search_forms.QueryForm(request.POST)
if query_form.is_valid():
query = Query.get(query_form['query_string'].value())
# Save search picks
searchpicks_formset = forms.SearchPromotionsFormSet(request.POST, instance=query)
if save_searchpicks(query, query, searchpicks_formset):
messages.success(request, _("Editor's picks for '{0}' created.").format(query), buttons=[
messages.button(reverse('wagtailsearchpromotions:edit', args=(query.id,)), _('Edit'))
])
return redirect('wagtailsearchpromotions:index')
else:
if len(searchpicks_formset.non_form_errors()):
# formset level error (e.g. no forms submitted)
messages.error(request, " ".join(error for error in searchpicks_formset.non_form_errors()))
else:
# specific errors will be displayed within form fields
messages.error(request, _("Recommendations have not been created due to errors"))
else:
searchpicks_formset = forms.SearchPromotionsFormSet()
else:
query_form = search_forms.QueryForm()
searchpicks_formset = forms.SearchPromotionsFormSet()
return TemplateResponse(request, 'wagtailsearchpromotions/add.html', {
'query_form': query_form,
'searchpicks_formset': searchpicks_formset,
'form_media': query_form.media + searchpicks_formset.media,
})
示例15: edit
# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import error [as 别名]
def edit(request, query_id):
query = get_object_or_404(Query, id=query_id)
if request.method == 'POST':
# Get query
query_form = search_forms.QueryForm(request.POST)
# and the recommendations
searchpicks_formset = forms.SearchPromotionsFormSet(request.POST, instance=query)
if query_form.is_valid():
new_query = Query.get(query_form['query_string'].value())
# Save search picks
if save_searchpicks(query, new_query, searchpicks_formset):
messages.success(request, _("Editor's picks for '{0}' updated.").format(new_query), buttons=[
messages.button(reverse('wagtailsearchpromotions:edit', args=(query.id,)), _('Edit'))
])
return redirect('wagtailsearchpromotions:index')
else:
if len(searchpicks_formset.non_form_errors()):
messages.error(request, " ".join(error for error in searchpicks_formset.non_form_errors()))
# formset level error (e.g. no forms submitted)
else:
messages.error(request, _("Recommendations have not been saved due to errors"))
# specific errors will be displayed within form fields
else:
query_form = search_forms.QueryForm(initial=dict(query_string=query.query_string))
searchpicks_formset = forms.SearchPromotionsFormSet(instance=query)
return TemplateResponse(request, 'wagtailsearchpromotions/edit.html', {
'query_form': query_form,
'searchpicks_formset': searchpicks_formset,
'query': query,
'form_media': query_form.media + searchpicks_formset.media,
})