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


Python NewsletterFooterForm.errors["__all__"]方法代码示例

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


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

示例1: contribute

# 需要导入模块: from bedrock.newsletter.forms import NewsletterFooterForm [as 别名]
# 或者: from bedrock.newsletter.forms.NewsletterFooterForm import errors["__all__"] [as 别名]
def contribute(request, template, return_to_form):
    newsletter_id = "about-mozilla"
    has_contribute_form = request.method == "POST" and "contribute-form" in request.POST

    has_newsletter_form = request.method == "POST" and "newsletter-form" in request.POST

    locale = getattr(request, "locale", "en-US")

    contribute_success = False
    newsletter_success = False

    # This is ugly, but we need to handle two forms. I would love if
    # these forms could post to separate pages and get redirected
    # back, but we're forced to keep the error/success workflow on the
    # same page. Please change this.
    if has_contribute_form:
        form = ContributeForm(request.POST)

        if form.is_valid():
            data = form.cleaned_data.copy()

            honeypot = data.pop("office_fax")

            if not honeypot:
                contribute_success = email_contribute.handle_form(request, form)
                if contribute_success:
                    # If form was submitted successfully, return a new, empty
                    # one.
                    form = ContributeForm()
            else:
                # send back a clean form if honeypot was filled in
                form = ContributeForm()
    else:
        form = ContributeForm()

    if has_newsletter_form:
        newsletter_form = NewsletterFooterForm(newsletter_id, locale, request.POST, prefix="newsletter")
        if newsletter_form.is_valid():
            data = newsletter_form.cleaned_data

            try:
                basket.subscribe(data["email"], newsletter_id, format=data["fmt"], country=data["country"])
                newsletter_success = True
            except basket.BasketException:
                msg = newsletter_form.error_class(
                    [_("We apologize, but an error occurred in our system. " "Please try again later.")]
                )
                newsletter_form.errors["__all__"] = msg
    else:
        newsletter_form = NewsletterFooterForm(newsletter_id, locale, prefix="newsletter")

    return l10n_utils.render(
        request,
        template,
        {
            "form": form,
            "contribute_success": contribute_success,
            "newsletter_form": newsletter_form,
            "newsletter_success": newsletter_success,
            "return_to_form": return_to_form,
            "hide_form": hide_contrib_form(request.locale),
        },
    )
开发者ID:josiah2595,项目名称:bedrock,代码行数:65,代码来源:views.py


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