本文整理汇总了Python中wagtail.wagtailadmin.messages.warning函数的典型用法代码示例。如果您正苦于以下问题:Python warning函数的具体用法?Python warning怎么用?Python warning使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了warning函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: revisions_revert
def revisions_revert(request, page_id, revision_id):
page = get_object_or_404(Page, id=page_id).specific
page_perms = page.permissions_for_user(request.user)
if not page_perms.can_edit():
raise PermissionDenied
revision = get_object_or_404(page.revisions, id=revision_id)
revision_page = revision.as_page_object()
content_type = ContentType.objects.get_for_model(page)
page_class = content_type.model_class()
edit_handler_class = page_class.get_edit_handler()
form_class = edit_handler_class.get_form_class(page_class)
form = form_class(instance=revision_page)
edit_handler = edit_handler_class(instance=revision_page, form=form)
user_avatar = render_to_string('wagtailadmin/shared/user_avatar.html', {'user': revision.user})
messages.warning(request, mark_safe(_("You are viewing a previous revision of this page from <b>%s</b> by %s") % (revision.created_at.strftime("%d %b %Y %H:%M"), user_avatar)))
return render(request, 'wagtailadmin/pages/edit.html', {
'page': page,
'revision': revision,
'is_revision': True,
'content_type': content_type,
'edit_handler': edit_handler,
'errors_debug': None,
'preview_modes': page.preview_modes,
'form': form, # Used in unit tests
})
开发者ID:digideskio,项目名称:wagtail,代码行数:32,代码来源:pages.py
示例2: index
def index(request):
form = SearchForm(placeholder=_("Search something"))
example_form = ExampleForm()
messages.success(request, _("Success message"), buttons=[
messages.button('', _('View live')),
messages.button('', _('Edit'))
])
messages.warning(request, _("Warning message"), buttons=[
messages.button('', _('View live')),
messages.button('', _('Edit'))
])
messages.error(request, _("Error message"), buttons=[
messages.button('', _('View live')),
messages.button('', _('Edit'))
])
paginator = Paginator(list(range(100)), 10)
page = paginator.page(2)
return render(request, 'wagtailstyleguide/base.html', {
'search_form': form,
'example_form': example_form,
'example_page': page,
})
开发者ID:potatolondon,项目名称:wagtail-gae,代码行数:27,代码来源:views.py
示例3: index
def index(request):
form = SearchForm(placeholder=_("Search something"))
example_form = ExampleForm()
messages.success(request, _("Success message"), buttons=[
messages.button('', _('View live')),
messages.button('', _('Edit'))
])
messages.warning(request, _("Warning message"), buttons=[
messages.button('', _('View live')),
messages.button('', _('Edit'))
])
messages.error(request, _("Error message"), buttons=[
messages.button('', _('View live')),
messages.button('', _('Edit'))
])
fake_pagination = {
'number': 1,
'previous_page_number': 1,
'next_page_number': 2,
'has_previous': True,
'has_next': True,
'paginator': {
'num_pages': 10,
},
}
return render(request, 'wagtailstyleguide/base.html', {
'search_form': form,
'example_form': example_form,
'fake_pagination': fake_pagination,
})
开发者ID:EricSchles,项目名称:wagtail,代码行数:35,代码来源:views.py
示例4: index
def index(request):
form = SearchForm(placeholder=_("Search something"))
example_form = ExampleForm()
messages.success(
request, _("Success message"), buttons=[messages.button("", _("View live")), messages.button("", _("Edit"))]
)
messages.warning(
request, _("Warning message"), buttons=[messages.button("", _("View live")), messages.button("", _("Edit"))]
)
messages.error(
request, _("Error message"), buttons=[messages.button("", _("View live")), messages.button("", _("Edit"))]
)
fake_pagination = {
"number": 1,
"previous_page_number": 1,
"next_page_number": 2,
"has_previous": True,
"has_next": True,
"paginator": {"num_pages": 10},
}
return render(
request,
"wagtailstyleguide/base.html",
{"search_form": form, "example_form": example_form, "fake_pagination": fake_pagination},
)
开发者ID:janrito,项目名称:wagtail,代码行数:30,代码来源:views.py
示例5: revisions_revert
def revisions_revert(request, page_id, revision_id):
page = get_object_or_404(Page, id=page_id).specific
page_perms = page.permissions_for_user(request.user)
if not page_perms.can_edit():
raise PermissionDenied
revision = get_object_or_404(page.revisions, id=revision_id)
revision_page = revision.as_page_object()
content_type = ContentType.objects.get_for_model(page)
page_class = content_type.model_class()
edit_handler_class = page_class.get_edit_handler()
form_class = edit_handler_class.get_form_class(page_class)
form = form_class(instance=revision_page)
edit_handler = edit_handler_class(instance=revision_page, form=form)
user_avatar = render_to_string("wagtailadmin/shared/user_avatar.html", {"user": revision.user})
messages.warning(
request,
mark_safe(
_("You are viewing a previous revision of this page from <b>%(created_at)s</b> by %(user)s")
% {"created_at": revision.created_at.strftime("%d %b %Y %H:%M"), "user": user_avatar}
),
)
return render(
request,
"wagtailadmin/pages/edit.html",
{
"page": page,
"revision": revision,
"is_revision": True,
"content_type": content_type,
"edit_handler": edit_handler,
"errors_debug": None,
"preview_modes": page.preview_modes,
"form": form, # Used in unit tests
},
)
开发者ID:mvantellingen,项目名称:wagtail,代码行数:42,代码来源:pages.py
示例6: edit
def edit(request, page_id):
latest_revision = get_object_or_404(Page, id=page_id).get_latest_revision()
page = get_object_or_404(Page, id=page_id).get_latest_revision_as_page()
parent = page.get_parent()
content_type = ContentType.objects.get_for_model(page)
page_perms = page.permissions_for_user(request.user)
if not page_perms.can_edit():
raise PermissionDenied
edit_handler_class = get_page_edit_handler(page.__class__)
form_class = edit_handler_class.get_form_class(page.__class__)
errors_debug = None
if request.POST:
form = form_class(request.POST, request.FILES, instance=page)
validate_page_form(form, parent, page)
if form.is_valid() and not page.locked:
page = form.save(commit=False)
is_publishing = bool(request.POST.get('action-publish')) and page_perms.can_publish()
is_submitting = bool(request.POST.get('action-submit'))
# Save revision
revision = page.save_revision(
user=request.user,
submitted_for_moderation=is_submitting,
)
# Publish
if is_publishing:
revision.publish()
# Notifications
if is_publishing:
messages.success(request, _("Page '{0}' published.").format(page.title), buttons=[
messages.button(page.url, _('View live')),
messages.button(reverse('wagtailadmin_pages:edit', args=(page_id,)), _('Edit'))
])
elif is_submitting:
messages.success(request, _("Page '{0}' submitted for moderation.").format(page.title), buttons=[
messages.button(reverse('wagtailadmin_pages:view_draft', args=(page_id,)), _('View draft')),
messages.button(reverse('wagtailadmin_pages:edit', args=(page_id,)), _('Edit'))
])
send_notification(page.get_latest_revision().id, 'submitted', request.user.id)
else:
messages.success(request, _("Page '{0}' updated.").format(page.title))
for fn in hooks.get_hooks('after_edit_page'):
result = fn(request, page)
if hasattr(result, 'status_code'):
return result
if is_publishing or is_submitting:
# we're done here - redirect back to the explorer
return redirect('wagtailadmin_explore', page.get_parent().id)
else:
# Just saving - remain on edit page for further edits
return redirect('wagtailadmin_pages:edit', page.id)
else:
if page.locked:
messages.error(request, _("The page could not be saved as it is locked"))
else:
messages.error(request, _("The page could not be saved due to validation errors"))
edit_handler = edit_handler_class(instance=page, form=form)
errors_debug = (
repr(edit_handler.form.errors)
+ repr([(name, formset.errors) for (name, formset) in edit_handler.form.formsets.items() if formset.errors])
)
else:
form = form_class(instance=page)
edit_handler = edit_handler_class(instance=page, form=form)
# Check for revisions still undergoing moderation and warn
if latest_revision and latest_revision.submitted_for_moderation:
messages.warning(request, _("This page is currently awaiting moderation"))
return render(request, 'wagtailadmin/pages/edit.html', {
'page': page,
'content_type': content_type,
'edit_handler': edit_handler,
'errors_debug': errors_debug,
'preview_modes': page.preview_modes,
'form': form, # Used in unit tests
})
开发者ID:pjdelport,项目名称:wagtail,代码行数:89,代码来源:pages.py
示例7: edit
#.........这里部分代码省略.........
page.url,
_('View live')
),
messages.button(
reverse('wagtailadmin_pages:edit', args=(page_id,)),
_('Edit')
)
])
elif is_submitting:
message = _(
"Page '{0}' has been submitted for moderation."
).format(
page.title
)
messages.success(request, message, buttons=[
messages.button(
reverse('wagtailadmin_pages:view_draft', args=(page_id,)),
_('View draft')
),
messages.button(
reverse('wagtailadmin_pages:edit', args=(page_id,)),
_('Edit')
)
])
if not send_notification(page.get_latest_revision().id, 'submitted', request.user.pk):
messages.error(request, _("Failed to send notifications to moderators"))
else: # Saving
if is_reverting:
message = _(
"Page '{0}' has been replaced with revision from {1}."
).format(
page.title,
previous_revision.created_at.strftime("%d %b %Y %H:%M")
)
else:
message = _(
"Page '{0}' has been updated."
).format(
page.title
)
messages.success(request, message)
for fn in hooks.get_hooks('after_edit_page'):
result = fn(request, page)
if hasattr(result, 'status_code'):
return result
if is_publishing or is_submitting:
# we're done here - redirect back to the explorer
if next_url:
# redirect back to 'next' url if present
return redirect(next_url)
# redirect back to the explorer
return redirect('wagtailadmin_explore', page.get_parent().id)
else:
# Just saving - remain on edit page for further edits
target_url = reverse('wagtailadmin_pages:edit', args=[page.id])
if next_url:
# Ensure the 'next' url is passed through again if present
target_url += '?next=%s' % urlquote(next_url)
return redirect(target_url)
else:
if page.locked:
messages.error(request, _("The page could not be saved as it is locked"))
else:
messages.error(request, _("The page could not be saved due to validation errors"))
edit_handler = edit_handler_class(instance=page, form=form)
errors_debug = (
repr(edit_handler.form.errors) +
repr([
(name, formset.errors)
for (name, formset) in edit_handler.form.formsets.items()
if formset.errors
])
)
else:
form = form_class(instance=page)
edit_handler = edit_handler_class(instance=page, form=form)
# Check for revisions still undergoing moderation and warn
if latest_revision and latest_revision.submitted_for_moderation:
messages.warning(request, _("This page is currently awaiting moderation"))
return render(request, 'wagtailadmin/pages/edit.html', {
'page': page,
'content_type': content_type,
'edit_handler': edit_handler,
'errors_debug': errors_debug,
'preview_modes': page.preview_modes,
'form': form,
'next': next_url,
})
开发者ID:barschool,项目名称:wagtail,代码行数:101,代码来源:pages.py
示例8: edit
#.........这里部分代码省略.........
# Go live must be before expire
go_live_at = cleaned_data.get('go_live_at')
expire_at = cleaned_data.get('expire_at')
if go_live_at and expire_at:
if go_live_at > expire_at:
msg = _('Go live date/time must be before expiry date/time')
form._errors['go_live_at'] = form.error_class([msg])
form._errors['expire_at'] = form.error_class([msg])
del cleaned_data['go_live_at']
del cleaned_data['expire_at']
# Expire must be in the future
expire_at = cleaned_data.get('expire_at')
if expire_at and expire_at < timezone.now():
form._errors['expire_at'] = form.error_class([_('Expiry date/time must be in the future')])
del cleaned_data['expire_at']
return cleaned_data
form.clean = clean
if form.is_valid() and not page.locked:
page = form.save(commit=False)
is_publishing = bool(request.POST.get('action-publish')) and page_perms.can_publish()
is_submitting = bool(request.POST.get('action-submit'))
# Save revision
revision = page.save_revision(
user=request.user,
submitted_for_moderation=is_submitting,
)
# Publish
if is_publishing:
revision.publish()
else:
# Set has_unpublished_changes flag
if page.live:
# To avoid overwriting the live version, we only save the page
# to the revisions table
Page.objects.filter(id=page.id).update(has_unpublished_changes=True)
else:
page.has_unpublished_changes = True
page.save()
# Notifications
if is_publishing:
messages.success(request, _("Page '{0}' published.").format(page.title), buttons=[
messages.button(page.url, _('View live')),
messages.button(reverse('wagtailadmin_pages_edit', args=(page_id,)), _('Edit'))
])
elif is_submitting:
messages.success(request, _("Page '{0}' submitted for moderation.").format(page.title), buttons=[
messages.button(reverse('wagtailadmin_pages_view_draft', args=(page_id,)), _('View draft')),
messages.button(reverse('wagtailadmin_pages_edit', args=(page_id,)), _('Edit'))
])
send_notification(page.get_latest_revision().id, 'submitted', request.user.id)
else:
messages.success(request, _("Page '{0}' updated.").format(page.title))
for fn in hooks.get_hooks('after_edit_page'):
result = fn(request, page)
if hasattr(result, 'status_code'):
return result
if is_publishing or is_submitting:
# we're done here - redirect back to the explorer
return redirect('wagtailadmin_explore', page.get_parent().id)
else:
# Just saving - remain on edit page for further edits
return redirect('wagtailadmin_pages_edit', page.id)
else:
if page.locked:
messages.error(request, _("The page could not be saved as it is locked"))
else:
messages.error(request, _("The page could not be saved due to validation errors"))
edit_handler = edit_handler_class(instance=page, form=form)
errors_debug = (
repr(edit_handler.form.errors)
+ repr([(name, formset.errors) for (name, formset) in edit_handler.form.formsets.items() if formset.errors])
)
else:
form = form_class(instance=page)
edit_handler = edit_handler_class(instance=page, form=form)
# Check for revisions still undergoing moderation and warn
if latest_revision and latest_revision.submitted_for_moderation:
messages.warning(request, _("This page is currently awaiting moderation"))
return render(request, 'wagtailadmin/pages/edit.html', {
'page': page,
'content_type': content_type,
'edit_handler': edit_handler,
'errors_debug': errors_debug,
'preview_modes': page.preview_modes,
'form': form, # Used in unit tests
})
开发者ID:cshoe,项目名称:wagtail,代码行数:101,代码来源:pages.py
注:本文中的wagtail.wagtailadmin.messages.warning函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论