本文整理汇总了Python中wagtail.admin.messages.button函数的典型用法代码示例。如果您正苦于以下问题:Python button函数的具体用法?Python button怎么用?Python button使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了button函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: edit
def edit(request, media_id):
Media = get_media_model()
MediaForm = get_media_form(Media)
media = get_object_or_404(Media, id=media_id)
if not permission_policy.user_has_permission_for_instance(request.user, 'change', media):
return permission_denied(request)
if request.POST:
original_file = media.file
form = MediaForm(request.POST, request.FILES, instance=media, user=request.user)
if form.is_valid():
if 'file' in form.changed_data:
# if providing a new media file, delete the old one.
# NB Doing this via original_file.delete() clears the file field,
# which definitely isn't what we want...
original_file.storage.delete(original_file.name)
media = form.save()
# Reindex the media entry to make sure all tags are indexed
for backend in get_search_backends():
backend.add(media)
messages.success(request, _("Media file '{0}' updated").format(media.title), buttons=[
messages.button(reverse('wagtailmedia:edit', args=(media.id,)), _('Edit'))
])
return redirect('wagtailmedia:index')
else:
messages.error(request, _("The media could not be saved due to errors."))
else:
form = MediaForm(instance=media, user=request.user)
filesize = None
# Get file size when there is a file associated with the Media object
if media.file:
try:
filesize = media.file.size
except OSError:
# File doesn't exist
pass
if not filesize:
messages.error(
request,
_("The file could not be found. Please change the source or delete the media file"),
buttons=[messages.button(reverse('wagtailmedia:delete', args=(media.id,)), _('Delete'))]
)
return render(request, "wagtailmedia/media/edit.html", {
'media': media,
'filesize': filesize,
'form': form,
'user_can_delete': permission_policy.user_has_permission_for_instance(
request.user, 'delete', media
),
})
开发者ID:torchbox,项目名称:wagtailmedia,代码行数:58,代码来源:media.py
示例2: edit
def edit(request, document_id):
Document = get_document_model()
DocumentForm = get_document_form(Document)
doc = get_object_or_404(Document, id=document_id)
if not permission_policy.user_has_permission_for_instance(request.user, 'change', doc):
return permission_denied(request)
if request.method == 'POST':
original_file = doc.file
form = DocumentForm(request.POST, request.FILES, instance=doc, user=request.user)
if form.is_valid():
doc = form.save()
if 'file' in form.changed_data:
doc.file_size = doc.file.size
# if providing a new document file, delete the old one.
# NB Doing this via original_file.delete() clears the file field,
# which definitely isn't what we want...
original_file.storage.delete(original_file.name)
# Reindex the document to make sure all tags are indexed
search_index.insert_or_update_object(doc)
messages.success(request, _("Document '{0}' updated").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(instance=doc, user=request.user)
try:
local_path = doc.file.path
except NotImplementedError:
# Document is hosted externally (eg, S3)
local_path = None
if local_path:
# Give error if document file doesn't exist
if not os.path.isfile(local_path):
messages.error(
request,
_("The file could not be found. Please change the source or delete the document"),
buttons=[messages.button(reverse('wagtaildocs:delete', args=(doc.id,)), _('Delete'))]
)
return render(request, "wagtaildocs/documents/edit.html", {
'document': doc,
'filesize': doc.get_file_size(),
'form': form,
'user_can_delete': permission_policy.user_has_permission_for_instance(
request.user, 'delete', doc
),
})
开发者ID:balazs-endresz,项目名称:wagtail,代码行数:57,代码来源:documents.py
示例3: 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
示例4: 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
示例5: add
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
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 render(request, "wagtaildocs/documents/add.html", {
'form': form,
})
开发者ID:balazs-endresz,项目名称:wagtail,代码行数:27,代码来源:documents.py
示例6: add
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
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 render(request, "wagtailimages/images/add.html", {
'form': form,
})
开发者ID:Henk-JanVanHasselaar,项目名称:wagtail,代码行数:28,代码来源:images.py
示例7: add
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 render(request, 'wagtailsearchpromotions/add.html', {
'query_form': query_form,
'searchpicks_formset': searchpicks_formset,
'form_media': query_form.media + searchpicks_formset.media,
})
开发者ID:BertrandBordage,项目名称:wagtail,代码行数:32,代码来源:views.py
示例8: revisions_unschedule
def revisions_unschedule(request, page_id, revision_id):
page = get_object_or_404(Page, id=page_id).specific
user_perms = UserPagePermissionsProxy(request.user)
if not user_perms.for_page(page).can_unschedule():
raise PermissionDenied
revision = get_object_or_404(page.revisions, id=revision_id)
next_url = get_valid_next_url_from_request(request)
subtitle = _('revision {0} of "{1}"').format(revision.id, page.get_admin_display_title())
if request.method == 'POST':
revision.approved_go_live_at = None
revision.save(update_fields=['approved_go_live_at'])
messages.success(request, _('Revision {0} of "{1}" unscheduled.').format(revision.id, page.get_admin_display_title()), buttons=[
messages.button(reverse('wagtailadmin_pages:edit', args=(page.id,)), _('Edit'))
])
if next_url:
return redirect(next_url)
return redirect('wagtailadmin_pages:revisions_index', page.id)
return render(request, 'wagtailadmin/pages/revisions/confirm_unschedule.html', {
'page': page,
'revision': revision,
'next': next_url,
'subtitle': subtitle
})
开发者ID:hellomrjack,项目名称:wagtail,代码行数:31,代码来源:pages.py
示例9: edit
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 render(request, "wagtailredirects/edit.html", {
'redirect': theredirect,
'form': form,
'user_can_delete': permission_policy.user_has_permission(request.user, 'delete'),
})
开发者ID:BertrandBordage,项目名称:wagtail,代码行数:26,代码来源:views.py
示例10: unpublish
def unpublish(request, page_id):
page = get_object_or_404(Page, id=page_id).specific
user_perms = UserPagePermissionsProxy(request.user)
if not user_perms.for_page(page).can_unpublish():
raise PermissionDenied
next_url = get_valid_next_url_from_request(request)
if request.method == 'POST':
include_descendants = request.POST.get("include_descendants", False)
page.unpublish()
if include_descendants:
live_descendant_pages = page.get_descendants().live().specific()
for live_descendant_page in live_descendant_pages:
if user_perms.for_page(live_descendant_page).can_unpublish():
live_descendant_page.unpublish()
messages.success(request, _("Page '{0}' unpublished.").format(page.get_admin_display_title()), buttons=[
messages.button(reverse('wagtailadmin_pages:edit', args=(page.id,)), _('Edit'))
])
if next_url:
return redirect(next_url)
return redirect('wagtailadmin_explore', page.get_parent().id)
return render(request, 'wagtailadmin/pages/confirm_unpublish.html', {
'page': page,
'next': next_url,
'live_descendant_count': page.get_descendants().live().count(),
})
开发者ID:hellomrjack,项目名称:wagtail,代码行数:33,代码来源:pages.py
示例11: create
def create(request):
group = Group()
if request.method == 'POST':
form = CSVGroupCreationForm(
request.POST, request.FILES, instance=group)
if form.is_valid():
form.save()
messages.success(
request,
_("Group '{0}' created. "
"Imported {1} user(s).").format(
group, group.user_set.count()),
buttons=[
messages.button(reverse('wagtailusers_groups:edit',
args=(group.id,)), _('Edit'))
]
)
return redirect('wagtailusers_groups:index')
messages.error(request, _(
"The group could not be created due to errors."))
else:
form = CSVGroupCreationForm(instance=group)
return render(request, 'csv_group_creation/create.html', {
'form': form
})
开发者ID:praekelt,项目名称:molo.surveys,代码行数:28,代码来源:views.py
示例12: add
def add(request, media_type):
Media = get_media_model()
MediaForm = get_media_form(Media)
if request.POST:
media = Media(uploaded_by_user=request.user, type=media_type)
form = MediaForm(request.POST, request.FILES, instance=media, user=request.user)
if form.is_valid():
form.save()
# Reindex the media entry to make sure all tags are indexed
for backend in get_search_backends():
backend.add(media)
messages.success(request, _("Media file '{0}' added.").format(media.title), buttons=[
messages.button(reverse('wagtailmedia:edit', args=(media.id,)), _('Edit'))
])
return redirect('wagtailmedia:index')
else:
messages.error(request, _("The media file could not be saved due to errors."))
else:
media = Media(uploaded_by_user=request.user, type=media_type)
form = MediaForm(user=request.user, instance=media)
return render(request, "wagtailmedia/media/add.html", {
'form': form,
'media_type': media_type,
})
开发者ID:torchbox,项目名称:wagtailmedia,代码行数:28,代码来源:media.py
示例13: form_valid
def form_valid(self, form):
self.form = form
self.object = self.save_instance()
success_message = self.get_success_message()
if success_message is not None:
messages.success(self.request, success_message, buttons=[
messages.button(reverse(self.edit_url_name, args=(self.object.id,)), _('Edit'))
])
return redirect(self.get_success_url())
开发者ID:Henk-JanVanHasselaar,项目名称:wagtail,代码行数:9,代码来源:generic.py
示例14: 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)
user = User(email='[email protected]')
return render(request, 'wagtailstyleguide/base.html', {
'search_form': form,
'example_form': example_form,
'example_page': page,
'user': user,
})
开发者ID:balazs-endresz,项目名称:wagtail,代码行数:30,代码来源:views.py
示例15: approve_moderation
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')
开发者ID:hellomrjack,项目名称:wagtail,代码行数:23,代码来源:pages.py
示例16: edit
def edit(request, app_label, model_name, pk):
model = get_snippet_model_from_url_params(app_label, model_name)
permission = get_permission_name('change', model)
if not request.user.has_perm(permission):
return permission_denied(request)
instance = get_object_or_404(model, pk=unquote(pk))
edit_handler = get_snippet_edit_handler(model)
form_class = edit_handler.get_form_class()
if request.method == 'POST':
form = form_class(request.POST, request.FILES, instance=instance)
if form.is_valid():
form.save()
messages.success(
request,
_("{snippet_type} '{instance}' updated.").format(
snippet_type=capfirst(model._meta.verbose_name_plural),
instance=instance
),
buttons=[
messages.button(reverse(
'wagtailsnippets:edit', args=(app_label, model_name, quote(instance.pk))
), _('Edit'))
]
)
return redirect('wagtailsnippets:list', app_label, model_name)
else:
messages.validation_error(
request, _("The snippet could not be saved due to errors."), form
)
edit_handler = edit_handler.bind_to_instance(instance=instance,
form=form,
request=request)
else:
form = form_class(instance=instance)
edit_handler = edit_handler.bind_to_instance(instance=instance,
form=form,
request=request)
return render(request, 'wagtailsnippets/snippets/edit.html', {
'model_opts': model._meta,
'instance': instance,
'edit_handler': edit_handler,
'form': form,
})
开发者ID:kaedroho,项目名称:wagtail,代码行数:49,代码来源:snippets.py
示例17: reject_moderation
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')
开发者ID:hellomrjack,项目名称:wagtail,代码行数:18,代码来源:pages.py
示例18: move_confirm
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 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'))
])
return redirect('wagtailadmin_explore', destination.id)
return render(request, 'wagtailadmin/pages/confirm_move.html', {
'page_to_move': page_to_move,
'destination': destination,
})
开发者ID:hellomrjack,项目名称:wagtail,代码行数:21,代码来源:pages.py
示例19: move_confirm
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 render(request, 'wagtailadmin/pages/confirm_move.html', {
'page_to_move': page_to_move,
'destination': destination,
})
开发者ID:Proper-Job,项目名称:wagtail,代码行数:38,代码来源:pages.py
示例20: edit
def edit(request, page_id):
real_page_record = get_object_or_404(Page, id=page_id)
latest_revision = real_page_record.get_latest_revision()
page = real_page_record.get_latest_revision_as_page()
parent = page.get_parent()
content_type = ContentType.objects.get_for_model(page)
page_class = content_type.model_class()
page_perms = page.permissions_for_user(request.user)
if not page_perms.can_edit():
raise PermissionDenied
for fn in hooks.get_hooks('before_edit_page'):
result = fn(request, page)
if hasattr(result, 'status_code'):
return result
edit_handler = page_class.get_edit_handler()
form_class = edit_handler.get_form_class()
next_url = get_valid_next_url_from_request(request)
errors_debug = None
if request.method == 'POST':
form = form_class(request.POST, request.FILES, instance=page,
parent_page=parent)
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'))
is_reverting = bool(request.POST.get('revision'))
# If a revision ID was passed in the form, get that revision so its
# date can be referenced in notification messages
if is_reverting:
previous_revision = get_object_or_404(page.revisions, id=request.POST.get('revision'))
# Save revision
revision = page.save_revision(
user=request.user,
submitted_for_moderation=is_submitting,
)
# store submitted go_live_at for messaging below
go_live_at = page.go_live_at
# Publish
if is_publishing:
revision.publish()
# Need to reload the page because the URL may have changed, and we
# need the up-to-date URL for the "View Live" button.
page = page.specific_class.objects.get(pk=page.pk)
# Notifications
if is_publishing:
if go_live_at and go_live_at > timezone.now():
# Page has been scheduled for publishing in the future
if is_reverting:
message = _(
"Revision from {0} of page '{1}' has been scheduled for publishing."
).format(
previous_revision.created_at.strftime("%d %b %Y %H:%M"),
page.get_admin_display_title()
)
else:
if page.live:
message = _(
"Page '{0}' is live and this revision has been scheduled for publishing."
).format(
page.get_admin_display_title()
)
else:
message = _(
"Page '{0}' has been scheduled for publishing."
).format(
page.get_admin_display_title()
)
messages.success(request, message, buttons=[
messages.button(
reverse('wagtailadmin_pages:edit', args=(page.id,)),
_('Edit')
)
])
else:
# Page is being published now
if is_reverting:
message = _(
"Revision from {0} of page '{1}' has been published."
).format(
previous_revision.created_at.strftime("%d %b %Y %H:%M"),
page.get_admin_display_title()
)
else:
#.........这里部分代码省略.........
开发者ID:hellomrjack,项目名称:wagtail,代码行数:101,代码来源:pages.py
注:本文中的wagtail.admin.messages.button函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论