本文整理汇总了Python中bedrock.newsletter.forms.NewsletterFooterForm.errors['email']方法的典型用法代码示例。如果您正苦于以下问题:Python NewsletterFooterForm.errors['email']方法的具体用法?Python NewsletterFooterForm.errors['email']怎么用?Python NewsletterFooterForm.errors['email']使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bedrock.newsletter.forms.NewsletterFooterForm
的用法示例。
在下文中一共展示了NewsletterFooterForm.errors['email']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: email_newsletter_form
# 需要导入模块: from bedrock.newsletter.forms import NewsletterFooterForm [as 别名]
# 或者: from bedrock.newsletter.forms.NewsletterFooterForm import errors['email'] [as 别名]
def email_newsletter_form(ctx, newsletters='mozilla-and-you', title=None,
include_country=True, include_language=True,
use_thankyou=True, footer=True, process_form=True):
request = ctx['request']
context = ctx.get_all()
context.update(dict(
id=newsletters,
title=title,
include_country=include_country,
include_language=include_language,
use_thankyou=use_thankyou,
footer=footer,
))
success = False
form = NewsletterFooterForm(newsletters, get_locale(request),
request.POST or None)
if process_form and request.method == 'POST':
if form.is_valid():
data = form.cleaned_data
# If data['lang'] is set, pass it to the template.
# If it's None, empty, or nonexistent, pass 'en'.
context['lang'] = data.get('lang', 'en').strip() or 'en'
kwargs = {'format': data['fmt']}
# add optional data
kwargs.update(dict((k, data[k]) for k in ['country',
'lang',
'source_url']
if data[k]))
try:
basket.subscribe(data['email'], form.newsletters,
**kwargs)
except basket.BasketException as e:
if e.code == basket.errors.BASKET_INVALID_EMAIL:
form.errors['email'] = form.error_class([invalid_email_address])
else:
log.exception("Error subscribing %s to newsletter %s" %
(data['email'], form.newsletters))
form.errors['__all__'] = form.error_class([general_error])
else:
success = True
request.newsletter_success = success
context.update(dict(form=form, success=success))
html = jingo.render_to_string(request, 'newsletter/includes/form.html', context)
if not (success and not use_thankyou):
return jinja2.Markup(html)