本文整理汇总了Python中bedrock.newsletter.forms.NewsletterFooterForm类的典型用法代码示例。如果您正苦于以下问题:Python NewsletterFooterForm类的具体用法?Python NewsletterFooterForm怎么用?Python NewsletterFooterForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NewsletterFooterForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_request
def process_request(self, request):
success = False
is_footer_form = (request.method == 'POST' and
'newsletter-footer' in request.POST)
if is_footer_form:
form = NewsletterFooterForm(request.locale, request.POST or None)
if form.is_valid():
data = form.cleaned_data
kwargs = {
'format': data['fmt'],
}
# add optional data
kwargs.update(dict((k, data[k]) for k in ['country',
'lang',
'source_url']
if data[k]))
result = newsletter_subscribe(data['email'])
request.newsletter_subscriber = data['email']
request.new_subscription = result
success = True
request.newsletter_form = form
else:
request.newsletter_form = NewsletterFooterForm(request.locale, None)
request.newsletter_success = success
示例2: one_newsletter_subscribe
def one_newsletter_subscribe(request, template_name, target=None):
success = False
# not in a footer, but we use the same form
form = NewsletterFooterForm(request.locale, request.POST or None)
if form.is_valid():
data = form.cleaned_data
request.newsletter_lang = data.get('lang', 'en') 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]))
newsletter_subscribe(data['email'])
success = True
request.newsletter_form = form
request.newsletter_success = success
return l10n_utils.render(request,
template_name,
{'target': target})
示例3: process_request
def process_request(self, request):
success = False
form = NewsletterFooterForm(request.locale, request.POST or None)
is_footer_form = (request.method == 'POST' and
'newsletter-footer' in request.POST)
if is_footer_form:
if form.is_valid():
data = form.cleaned_data
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'], data['newsletter'],
**kwargs)
success = True
except basket.BasketException:
msg = _lazy("We are sorry, but there was a problem "
"with our system. Please try again later!")
form.errors['__all__'] = form.error_class([msg])
request.newsletter_form = form
request.newsletter_success = success
示例4: test_invalid_newsletter_is_error
def test_invalid_newsletter_is_error(self):
"""Invalid newsletter should not raise exception. Bug 1072302.
Instead, an invalid newsletter name should manifest as a normal
form error.
"""
data = {
'email': '[email protected]',
'lang': 'fr',
'privacy': True,
'fmt': 'H',
'newsletters': '',
}
form = NewsletterFooterForm('', locale='en-US', data=data.copy())
self.assertFalse(form.is_valid())
self.assertIn('newsletters', form.errors)
self.assertEqual(form.errors['newsletters'], [u'This field is required.'])
invalid_newsletter = '[email protected]'
data = {
'email': '[email protected]',
'lang': 'fr',
'privacy': True,
'fmt': 'H',
'newsletters': invalid_newsletter,
}
form = NewsletterFooterForm(invalid_newsletter, locale='en-US', data=data.copy())
self.assertFalse(form.is_valid())
self.assertIn('newsletters', form.errors)
self.assertEqual(form.errors['newsletters'], [u'Invalid Newsletter'])
示例5: contribute
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)
contribute_success = email_contribute.handle_form(request, form)
if contribute_success:
# If form was submitted successfully, return a new, empty
# one.
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),
'has_moz15': locale in settings.LOCALES_WITH_MOZ15})
示例6: test_lang_not_required
def test_lang_not_required(self):
"""lang not required since field not always displayed"""
data = {"email": "[email protected]", "privacy": True, "fmt": "H", "newsletters": self.newsletter_name}
form = NewsletterFooterForm(self.newsletter_name, locale="en-US", data=data.copy())
self.assertTrue(form.is_valid(), form.errors)
# Form returns '' for lang, so we don't accidentally change the user's
# preferred language thinking they entered something here that they
# didn't.
self.assertEqual(u"", form.cleaned_data["lang"])
示例7: test_privacy_required
def test_privacy_required(self):
"""they have to check the privacy box"""
data = {
'email': '[email protected]',
'privacy': False,
'fmt': 'H',
'newsletters': self.newsletter_name,
}
form = NewsletterFooterForm(self.newsletter_name, locale='en-US', data=data)
self.assertFalse(form.is_valid())
self.assertIn('privacy', form.errors)
示例8: test_multiple_newsletters
def test_multiple_newsletters(self):
"""Should allow to subscribe to multiple newsletters at a time."""
newsletters = "mozilla-and-you,beta"
data = {"email": "[email protected]", "lang": "en", "privacy": "Y", "fmt": "H", "newsletters": newsletters}
form = NewsletterFooterForm(newsletters, "en-US", data=data.copy())
self.assertTrue(form.is_valid())
self.assertEqual(form.cleaned_data["newsletters"], newsletters)
# whitespace shouldn't matter
form = NewsletterFooterForm("mozilla-and-you , beta ", "en-US", data=data.copy())
self.assertTrue(form.is_valid())
self.assertEqual(form.cleaned_data["newsletters"], newsletters)
示例9: test_form
def test_form(self):
"""Form works normally"""
data = {
'email': '[email protected]',
'lang': 'fr',
'privacy': True,
'fmt': 'H',
}
form = NewsletterFooterForm(self.newsletter_name, locale='en-US', data=data)
self.assertTrue(form.is_valid(), form.errors)
cleaned_data = form.cleaned_data
self.assertEqual(data['fmt'], cleaned_data['fmt'])
self.assertEqual(data['lang'], cleaned_data['lang'])
示例10: test_lang_not_required
def test_lang_not_required(self):
"""lang not required since field not always displayed"""
data = {
'email': '[email protected]',
'privacy': True,
'fmt': 'H',
}
form = NewsletterFooterForm(self.newsletter_name, locale='en-US', data=data)
self.assertTrue(form.is_valid(), form.errors)
# Form returns '' for lang, so we don't accidentally change the user's
# preferred language thinking they entered something here that they
# didn't.
self.assertEqual(u'', form.cleaned_data['lang'])
示例11: test_form
def test_form(self):
"""Form works normally"""
data = {
"email": "[email protected]",
"lang": "fr",
"privacy": True,
"fmt": "H",
"newsletters": self.newsletter_name,
}
form = NewsletterFooterForm(self.newsletter_name, locale="en-US", data=data.copy())
self.assertTrue(form.is_valid(), form.errors)
cleaned_data = form.cleaned_data
self.assertEqual(data["fmt"], cleaned_data["fmt"])
self.assertEqual(data["lang"], cleaned_data["lang"])
示例12: email_newsletter_form
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:
log.exception("Error subscribing %s to newsletter %s" %
(data['email'], newsletters))
msg = _lazy("We are sorry, but there was a problem "
"with our system. Please try again later!")
form.errors['__all__'] = form.error_class([msg])
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)
示例13: test_source_url_too_long
def test_source_url_too_long(self):
"""Form works normally"""
data = {
'email': '[email protected]',
'lang': 'fr',
'first_name': 'Walter',
'last_name': 'Sobchak',
'privacy': True,
'fmt': 'H',
'source_url': 'about:devtools' * 20,
'newsletters': self.newsletter_name,
}
form = NewsletterFooterForm(self.newsletter_name, locale='en-US', data=data.copy())
self.assertTrue(form.is_valid(), form.errors)
cleaned_data = form.cleaned_data
self.assertEqual(data['source_url'][:255], cleaned_data['source_url'])
示例14: test_multiple_newsletters
def test_multiple_newsletters(self):
"""Should allow to subscribe to multiple newsletters at a time."""
data = {
'email': '[email protected]',
'lang': 'en',
'privacy': 'Y',
'fmt': 'H',
}
form = NewsletterFooterForm('mozilla-and-you,beta', 'en-US', data=data.copy())
self.assertTrue(form.is_valid())
self.assertEqual(form.newsletters, 'mozilla-and-you,beta')
# whitespace shouldn't matter
form = NewsletterFooterForm('mozilla-and-you , beta ', 'en-US', data=data.copy())
self.assertTrue(form.is_valid())
self.assertEqual(form.newsletters, 'mozilla-and-you,beta')
示例15: test_form
def test_form(self):
"""Form works normally"""
data = {
'email': '[email protected]',
'lang': 'fr',
'first_name': 'Walter',
'last_name': 'Sobchak',
'privacy': True,
'fmt': 'H',
'source_url': 'https://accounts.firefox.com',
'newsletters': self.newsletter_name,
}
form = NewsletterFooterForm(self.newsletter_name, locale='en-US', data=data.copy())
self.assertTrue(form.is_valid(), form.errors)
cleaned_data = form.cleaned_data
self.assertEqual(data['fmt'], cleaned_data['fmt'])
self.assertEqual(data['lang'], cleaned_data['lang'])
self.assertEqual(data['source_url'], cleaned_data['source_url'])