当前位置: 首页>>代码示例>>Python>>正文


Python messages.success方法代码示例

本文整理汇总了Python中wagtail.admin.messages.success方法的典型用法代码示例。如果您正苦于以下问题:Python messages.success方法的具体用法?Python messages.success怎么用?Python messages.success使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wagtail.admin.messages的用法示例。


在下文中一共展示了messages.success方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: approve_moderation

# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import success [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') 
开发者ID:wagtail,项目名称:wagtail,代码行数:25,代码来源:pages.py

示例2: reject_moderation

# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import success [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') 
开发者ID:wagtail,项目名称:wagtail,代码行数:20,代码来源:pages.py

示例3: unlock

# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import success [as 别名]
def unlock(request, page_id):
    # Get the page
    page = get_object_or_404(Page, id=page_id).specific

    # Check permissions
    if not page.permissions_for_user(request.user).can_unlock():
        raise PermissionDenied

    # Unlock the page
    if page.locked:
        page.locked = False
        page.locked_by = None
        page.locked_at = None
        page.save()

        messages.success(request, _("Page '{0}' is now unlocked.").format(page.get_admin_display_title()), extra_tags='unlock')

    # Redirect
    redirect_to = request.POST.get('next', None)
    if redirect_to and is_safe_url(url=redirect_to, allowed_hosts={request.get_host()}):
        return redirect(redirect_to)
    else:
        return redirect('wagtailadmin_explore', page.get_parent().id) 
开发者ID:wagtail,项目名称:wagtail,代码行数:25,代码来源:pages.py

示例4: create

# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import success [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,
    }) 
开发者ID:wagtail,项目名称:wagtail,代码行数:27,代码来源:users.py

示例5: delete

# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import success [as 别名]
def delete(request, user_id):
    user = get_object_or_404(User, pk=user_id)

    if not user_can_delete_user(request.user, user):
        return permission_denied(request)

    for fn in hooks.get_hooks('before_delete_user'):
        result = fn(request, user)
        if hasattr(result, 'status_code'):
            return result
    if request.method == 'POST':
        user.delete()
        messages.success(request, _("User '{0}' deleted.").format(user))
        for fn in hooks.get_hooks('after_delete_user'):
            result = fn(request, user)
            if hasattr(result, 'status_code'):
                return result
        return redirect('wagtailusers_users:index')

    return TemplateResponse(request, "wagtailusers/users/confirm_delete.html", {
        'user': user,
    }) 
开发者ID:wagtail,项目名称:wagtail,代码行数:24,代码来源:users.py

示例6: delete

# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import success [as 别名]
def delete(request, redirect_id):
    theredirect = get_object_or_404(models.Redirect, id=redirect_id)

    if not permission_policy.user_has_permission_for_instance(
        request.user, 'delete', theredirect
    ):
        return permission_denied(request)

    if request.method == 'POST':
        theredirect.delete()
        messages.success(request, _("Redirect '{0}' deleted.").format(theredirect.title))
        return redirect('wagtailredirects:index')

    return TemplateResponse(request, "wagtailredirects/confirm_delete.html", {
        'redirect': theredirect,
    }) 
开发者ID:wagtail,项目名称:wagtail,代码行数:18,代码来源:views.py

示例7: unpublish

# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import success [as 别名]
def unpublish(request, pk, newsitem_pk):
    newsindex = get_object_or_404(
        Page.objects.specific().type(NewsIndexMixin), pk=pk)
    NewsItem = newsindex.get_newsitem_model()

    if not request.user.has_perms(format_perms(NewsItem, ['change'])):
        raise PermissionDenied()

    newsitem = get_object_or_404(NewsItem, newsindex=newsindex, pk=newsitem_pk)

    if request.method == 'POST':
        newsitem.unpublish()
        messages.success(request, _('{} has been unpublished').format(newsitem), [
            (reverse('wagtailnews:edit', kwargs={'pk': pk, 'newsitem_pk': newsitem_pk}), _('Edit')),
        ])
        signals.newsitem_unpublished.send(sender=NewsItem, instance=newsitem)
        return redirect('wagtailnews:index', pk=pk)

    return render(request, 'wagtailnews/unpublish.html', {
        'newsindex': newsindex,
        'newsitem': newsitem,
        'newsitem_perms': perms_for_template(request, NewsItem),
    }) 
开发者ID:neon-jungle,项目名称:wagtailnews,代码行数:25,代码来源:editor.py

示例8: form_valid

# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import success [as 别名]
def form_valid(self, form):
        form.save()
        messages.success(self.request, _("Main menu updated successfully."))
        return redirect(self.edit_url) 
开发者ID:rkhleics,项目名称:wagtailmenus,代码行数:6,代码来源:views.py

示例9: form_valid

# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import success [as 别名]
def form_valid(self, form):
        self.form = form
        self.object = self.save_instance()
        success_message = self.get_success_message(self.object)
        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:wagtail,项目名称:wagtail,代码行数:11,代码来源:generic.py

示例10: delete

# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import success [as 别名]
def delete(self, request, *args, **kwargs):
        response = super().delete(request, *args, **kwargs)
        messages.success(request, self.get_success_message())
        return response 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:generic.py

示例11: post

# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import success [as 别名]
def post(self, request, instance_id):
        self.object = get_object_or_404(self.get_queryset(), id=instance_id)
        collection_contents = self.get_collection_contents()

        if collection_contents:
            # collection is non-empty; refuse to delete it
            return HttpResponseForbidden()

        self.object.delete()
        messages.success(request, self.success_message.format(self.object))
        return redirect(self.index_url_name) 
开发者ID:wagtail,项目名称:wagtail,代码行数:13,代码来源:collections.py

示例12: delete

# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import success [as 别名]
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 TemplateResponse(request, 'wagtailadmin/pages/confirm_delete.html', {
        'page': page,
        'descendant_count': page.get_descendant_count(),
        'next': next_url,
    }) 
开发者ID:wagtail,项目名称:wagtail,代码行数:35,代码来源:pages.py

示例13: move_confirm

# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import success [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,
    }) 
开发者ID:wagtail,项目名称:wagtail,代码行数:40,代码来源:pages.py

示例14: revisions_unschedule

# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import success [as 别名]
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 TemplateResponse(request, 'wagtailadmin/pages/revisions/confirm_unschedule.html', {
        'page': page,
        'revision': revision,
        'next': next_url,
        'subtitle': subtitle
    }) 
开发者ID:wagtail,项目名称:wagtail,代码行数:33,代码来源:pages.py

示例15: add

# 需要导入模块: from wagtail.admin import messages [as 别名]
# 或者: from wagtail.admin.messages import success [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,
    }) 
开发者ID:wagtail,项目名称:wagtail,代码行数:35,代码来源:images.py


注:本文中的wagtail.admin.messages.success方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。