• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python messages.error函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中wagtail.wagtailadmin.messages.error函数的典型用法代码示例。如果您正苦于以下问题:Python error函数的具体用法?Python error怎么用?Python error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: edit

def edit(request, group_id):
    group = get_object_or_404(Group, id=group_id)
    GroupPagePermissionFormSet = inlineformset_factory(
        Group,
        GroupPagePermission,
        formset=BaseGroupPagePermissionFormSet,
        extra=0
    )
    if request.POST:
        form = GroupForm(request.POST, instance=group)
        formset = GroupPagePermissionFormSet(request.POST, instance=group)
        if form.is_valid() and formset.is_valid():
            group = form.save()
            formset.save()
            messages.success(request, _("Group '{0}' updated.").format(group), buttons = [
                messages.button(reverse('wagtailusers_groups_edit', args=(group.id,)), _('Edit'))
            ])
            return redirect('wagtailusers_groups_index')
        else:
            messages.error(request, _("The group could not be saved due to errors."))
    else:
        form = GroupForm(instance=group)
        formset = GroupPagePermissionFormSet(instance=group)

    return render(request, 'wagtailusers/groups/edit.html', {
        'group': group,
        'form': form,
        'formset': formset,
    })
开发者ID:akrawchyk,项目名称:wagtail,代码行数:29,代码来源:groups.py


示例2: edit

def edit(request, image_id):
    Image = get_image_model()
    ImageForm = get_image_form(Image)

    image = get_object_or_404(Image, id=image_id)

    if not image.is_editable_by_user(request.user):
        raise PermissionDenied

    if request.POST:
        original_file = image.file
        form = ImageForm(request.POST, request.FILES, instance=image)
        if form.is_valid():
            if 'file' in form.changed_data:
                # if providing a new image file, delete the old one and all renditions.
                # 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)
                image.renditions.all().delete()

                # Set new image file size
                image.file_size = image.file.size

            form.save()

            # Reindex the image to make sure all tags are indexed
            for backend in get_search_backends():
                backend.add(image)

            messages.success(request, _("Image '{0}' updated.").format(image.title), buttons=[
                messages.button(reverse('wagtailimages:edit', args=(image.id,)), _('Edit again'))
            ])
            return redirect('wagtailimages:index')
        else:
            messages.error(request, _("The image could not be saved due to errors."))
    else:
        form = ImageForm(instance=image)

    # Check if we should enable the frontend url generator
    try:
        reverse('wagtailimages_serve', args=('foo', '1', 'bar'))
        url_generator_enabled = True
    except NoReverseMatch:
        url_generator_enabled = False

    if image.is_stored_locally():
        # Give error if image file doesn't exist
        if not os.path.isfile(image.file.path):
            messages.error(request, _(
                "The source image file could not be found. Please change the source or delete the image."
            ).format(image.title), buttons=[
                messages.button(reverse('wagtailimages:delete', args=(image.id,)), _('Delete'))
            ])

    return render(request, "wagtailimages/images/edit.html", {
        'image': image,
        'form': form,
        'url_generator_enabled': url_generator_enabled,
        'filesize': image.get_file_size(),
    })
开发者ID:CorneliusIV,项目名称:wagtail,代码行数:60,代码来源:images.py


示例3: 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:kapito,项目名称:wagtail,代码行数:26,代码来源:views.py


示例4: 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:robmoorman,项目名称:wagtail,代码行数:28,代码来源:images.py


示例5: create

def create(request):
    GroupPagePermissionFormSet = inlineformset_factory(
        Group,
        GroupPagePermission,
        formset=BaseGroupPagePermissionFormSet,
        extra=0
    )
    if request.POST:
        form = GroupForm(request.POST)
        formset = GroupPagePermissionFormSet(request.POST)
        if form.is_valid() and formset.is_valid():
            group = form.save()
            formset.instance = group
            formset.save()
            messages.success(request, _("Group '{0}' created.").format(group), buttons = [
                messages.button(reverse('wagtailusers_groups_edit', args=(group.id,)), _('Edit'))
            ])
            return redirect('wagtailusers_groups_index')
        else:
            messages.error(request, _("The group could not be created due to errors."))
    else:
        form = GroupForm()
        formset = GroupPagePermissionFormSet()

    return render(request, 'wagtailusers/groups/create.html', {
        'form': form,
        'formset': formset,
    })
开发者ID:akrawchyk,项目名称:wagtail,代码行数:28,代码来源:groups.py


示例6: create

def create(request):
    group = Group()
    if request.POST:
        form = GroupForm(request.POST, instance=group)
        permission_panels = [
            cls(request.POST, instance=group)
            for cls in get_permission_panel_classes()
        ]
        if form.is_valid() and all(panel.is_valid() for panel in permission_panels):
            form.save()

            for panel in permission_panels:
                panel.save()

            messages.success(request, _("Group '{0}' created.").format(group), buttons=[
                messages.button(reverse('wagtailusers_groups:edit', args=(group.id,)), _('Edit'))
            ])
            return redirect('wagtailusers_groups:index')
        else:
            messages.error(request, _("The group could not be created due to errors."))
    else:
        form = GroupForm(instance=group)
        permission_panels = [
            cls(instance=group)
            for cls in get_permission_panel_classes()
        ]

    return render(request, 'wagtailusers/groups/create.html', {
        'form': form,
        'permission_panels': permission_panels,
    })
开发者ID:Anlim,项目名称:wagtail,代码行数:31,代码来源:groups.py


示例7: post

    def post(self, request, *args, **kwargs):
        if not request.user.email:
            messages.error(
                request, _(
                    "Your email address is not configured. "
                    "Please update it before exporting."))
            return redirect(request.path)

        drf__date_joined__gte = request.GET.get('drf__date_joined__gte')
        drf__date_joined__lte = request.GET.get('drf__date_joined__lte')
        is_active_exact = request.GET.get('is_active__exact')

        filter_list = {
            'date_joined__range': (drf__date_joined__gte,
                                   drf__date_joined__lte) if
            drf__date_joined__gte and drf__date_joined__lte else None,
            'is_active': is_active_exact
        }

        arguments = {}

        for key, value in filter_list.items():
            if value:
                arguments[key] = value

        self.send_export_email_to_celery(request.user.email, arguments)
        messages.success(request, _(
            "CSV emailed to '{0}'").format(request.user.email))
        return redirect(request.path)
开发者ID:praekelt,项目名称:molo.profiles,代码行数:29,代码来源:admin_views.py


示例8: add

def add(request):
    EmbedVideoModel = get_embed_video_model()
    EmbedVideoForm = get_embed_video_form(EmbedVideoModel)

    if request.method == 'POST':
        embed_video = EmbedVideoModel(uploaded_by_user=request.user)
        form = EmbedVideoForm(request.POST, request.FILES, instance=embed_video, user=request.user)
        if form.is_valid():
            form.save()

            # Reindex the embed video to make sure all tags are indexed
            search_index.insert_or_update_object(embed_video)

            messages.success(
                request,
                _("Video '{0}' added.").format(embed_video.title),
                buttons=[
                    messages.button(
                        reverse(
                            'wagtail_embed_videos:edit',
                            args=(embed_video.id,)
                        ),
                        _('Edit')
                    )
                ]
            )
            return redirect('wagtail_embed_videos:index')
        else:
            messages.error(request, _("The video could not be created due to errors."))
    else:
        form = EmbedVideoForm(user=request.user)

    return render(request, "wagtail_embed_videos/embed_videos/add.html", {
        'form': form,
    })
开发者ID:SalahAdDin,项目名称:wagtail-embedvideos,代码行数:35,代码来源:embed_videos.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.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:thrawny,项目名称:wagtail,代码行数:30,代码来源:views.py


示例10: 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


示例11: add

def add(request):
    if request.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,
    })
开发者ID:Anlim,项目名称:wagtail,代码行数:31,代码来源:views.py


示例12: add

def add(request):
    theredirect = models.Redirect()

    form_class = REDIRECT_EDIT_HANDLER.get_form_class(models.Redirect)
    if request.POST:
        form = form_class(request.POST, request.FILES)
        if form.is_valid():
            theredirect = form.save(commit=False)
            theredirect.site = request.site
            theredirect.save()

            messages.success(request, _("Redirect '{0}' added.").format(theredirect.title), buttons=[
                messages.button(reverse('wagtailredirects_edit_redirect', args=(theredirect.id,)), _('Edit'))
            ])
            return redirect('wagtailredirects_index')
        else:
            messages.error(request, _("The redirect could not be created due to errors."))
            edit_handler = REDIRECT_EDIT_HANDLER(instance=theredirect, form=form)
    else:
        form = form_class()
        edit_handler = REDIRECT_EDIT_HANDLER(instance=theredirect, form=form)

    return render(request, "wagtailredirects/add.html", {
        'edit_handler': edit_handler,
    })
开发者ID:akrawchyk,项目名称:wagtail,代码行数:25,代码来源:views.py


示例13: permission_denied

def permission_denied(request):
    """Return a standard 'permission denied' response"""
    from wagtail.wagtailadmin import messages

    messages.error(
        request, _('Sorry, you do not have permission to access this area.'))
    return redirect('wagtailadmin_home')
开发者ID:ycanales,项目名称:wagtailmodeladmin,代码行数:7,代码来源:utils.py


示例14: edit

def edit(request, embed_video_id):
    EmbedVideo = get_embed_video_model()
    EmbedVideoForm = get_embed_video_form(EmbedVideo)

    embed_video = get_object_or_404(EmbedVideo, id=embed_video_id)

    if not embed_video.is_editable_by_user(request.user):
        raise PermissionDenied

    if request.POST:
        form = EmbedVideoForm(request.POST, request.FILES, instance=embed_video)
        if form.is_valid():
            form.save()

            # Reindex the embed_video to make sure all tags are indexed
            for backend in get_search_backends():
                backend.add(embed_video)

            messages.success(request, _("Embed video '{0}' updated.").format(embed_video.title), buttons=[
                messages.button(reverse('wagtail_embed_videos_edit_embed_video', args=(embed_video.id,)), _('Edit again'))
            ])
            return redirect('wagtail_embed_videos_index')
        else:
            messages.error(request, _("The embed video could not be saved due to errors."))
    else:
        form = EmbedVideoForm(instance=embed_video)

    return render(request, "wagtail_embed_videos/embed_videos/edit.html", {
        'embed_video': embed_video,
        'form': form,
    })
开发者ID:MariusCC,项目名称:wagtail-embedvideos,代码行数:31,代码来源:embed_videos.py


示例15: add

def add(request):
    Document = get_document_model()
    DocumentForm = get_document_form(Document)

    if request.POST:
        doc = Document(uploaded_by_user=request.user)
        form = DocumentForm(request.POST, request.FILES, instance=doc, user=request.user)
        if form.is_valid():
            form.save()

            # Reindex the document to make sure all tags are indexed
            for backend in get_search_backends():
                backend.add(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:Jimmy570,项目名称:wagtail,代码行数:26,代码来源:documents.py


示例16: edit

def edit(request, group_id):
    group = get_object_or_404(Group, id=group_id)
    if request.method == 'POST':
        form = GroupForm(request.POST, instance=group)
        permission_panels = [
            cls(request.POST, instance=group)
            for cls in get_permission_panel_classes()
        ]
        if form.is_valid() and all(panel.is_valid() for panel in permission_panels):
            form.save()

            for panel in permission_panels:
                panel.save()

            messages.success(request, _("Group '{0}' updated.").format(group), buttons=[
                messages.button(reverse('wagtailusers_groups:edit', args=(group.id,)), _('Edit'))
            ])
            return redirect('wagtailusers_groups:index')
        else:
            messages.error(request, _("The group could not be saved due to errors."))
    else:
        form = GroupForm(instance=group)
        permission_panels = [
            cls(instance=group)
            for cls in get_permission_panel_classes()
        ]

    return render(request, 'wagtailusers/groups/edit.html', {
        'group': group,
        'form': form,
        'permission_panels': permission_panels,
    })
开发者ID:DimiC,项目名称:wagtail,代码行数:32,代码来源:groups.py


示例17: 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()
        messages.success(
            request,
            _("Page '{0}' published.").format(revision.page.get_admin_display_title()),
            buttons=[
                messages.button(revision.page.url, _("View live")),
                messages.button(reverse("wagtailadmin_pages:edit", args=(revision.page.id,)), _("Edit")),
            ],
        )
        if not send_notification(revision.id, "approved", request.user.pk):
            messages.error(request, _("Failed to send approval notifications"))

    return redirect("wagtailadmin_home")
开发者ID:mvantellingen,项目名称:wagtail,代码行数:26,代码来源:pages.py


示例18: 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


示例19: post

    def post(self, request, *args, **kwargs):
        if request.POST:
            try:
                self.delete_instance()
                messages.success(
                    request,
                    _("{model} '{instance}' deleted.").format(
                        model=self.model_name, instance=self.instance))
                return redirect(self.get_index_url)
            except models.ProtectedError:
                messages.error(
                    request, _(
                        "{model} '{instance}' could not be deleted."
                    ).format(model=self.model_name, instance=self.instance))

                linked_objects = []
                for rel in self.model._meta.get_all_related_objects():
                    if rel.on_delete == models.PROTECT:
                        qs = getattr(self.instance, rel.get_accessor_name())
                        for obj in qs.all():
                            linked_objects.append(obj)

                context = {
                    'view': self,
                    'instance': self.instance,
                    'error_protected': True,
                    'linked_objects': linked_objects,
                }
        return self.render_to_response(context)
开发者ID:Luperi,项目名称:wagtailmodeladmin,代码行数:29,代码来源:views.py


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python messages.success函数代码示例发布时间:2022-05-26
下一篇:
Python messages.button函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap