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
def process_request(self, request): success = False form = NewsletterForm(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
def __init__(self, newsletters, locale, data=None, *args, **kwargs): regions = product_details.get_regions(locale) regions = sorted(iter(regions.items()), key=itemgetter(1)) try: newsletters = validate_newsletters(newsletters) except ValidationError: # replace with most common good newsletter # form validation will work with submitted data newsletters = 'mozilla-and-you' lang = locale.lower() if '-' in lang: lang, country = lang.split('-', 1) else: country = '' if lang_file_has_tag('mozorg/newsletters', locale, 'country_region_122019'): regions.insert(0, ('', _lazy('Select country or region'))) else: regions.insert(0, ('', _lazy('Select country'))) lang_choices = get_lang_choices(newsletters) languages = [x[0] for x in lang_choices] if lang not in languages: # The lang from their locale is not one that our newsletters # are translated into. Initialize the language field to no # choice, to force the user to pick one of the languages that # we do support. lang = '' lang_choices.insert(0, ('', _lazy('Available Languages'))) super(NewsletterFooterForm, self).__init__(data, *args, **kwargs) required_args = { 'required': 'required', 'aria-required': 'true', } country_widget = widgets.Select(attrs=required_args) self.fields['country'] = forms.ChoiceField(widget=country_widget, choices=regions, initial=country, required=False) lang_widget = widgets.Select(attrs=required_args) self.fields['lang'] = forms.TypedChoiceField(widget=lang_widget, choices=lang_choices, initial=lang, required=False) self.fields['newsletters'].initial = newsletters
def __init__(self, newsletters, locale, data=None, *args, **kwargs): regions = product_details.get_regions(locale) regions = sorted(regions.iteritems(), key=itemgetter(1)) try: newsletters = validate_newsletters(newsletters) except ValidationError: # replace with most common good newsletter # form validation will work with submitted data newsletters = 'mozilla-and-you' lang = locale.lower() if '-' in lang: lang, country = lang.split('-', 1) else: country = '' regions.insert(0, ('', _lazy('Select country'))) lang_choices = get_lang_choices(newsletters) languages = [x[0] for x in lang_choices] if lang not in languages: # The lang from their locale is not one that our newsletters # are translated into. Initialize the language field to no # choice, to force the user to pick one of the languages that # we do support. lang = '' lang_choices.insert(0, ('', _lazy('Available Languages'))) super(NewsletterFooterForm, self).__init__(data, *args, **kwargs) required_args = { 'required': 'required', 'aria-required': 'true', } country_widget = widgets.Select(attrs=required_args) self.fields['country'] = forms.ChoiceField(widget=country_widget, choices=regions, initial=country, required=False) lang_widget = widgets.Select(attrs=required_args) self.fields['lang'] = forms.TypedChoiceField(widget=lang_widget, choices=lang_choices, initial=lang, required=False) self.fields['newsletters'].initial = newsletters
def test_gettext_lazy_searches_kwarg_specified_lang_files(self, trans_patch): """ The `l10n_utils.dotlang._lazy` function should search .lang files specified in the `lang_files` keyword arg, and not the ones from the module. """ # test the case when LANG_FILES is a string trans_str = 'Translate me' # have to call __unicode__ directly because the value is a Mock # object, and the `unicode()` function throws an exception. _lazy(trans_str, lang_files='maude').__unicode__() call_lang_files = ['maude'] + settings.DOTLANG_FILES trans_patch.assert_called_with(trans_str, call_lang_files) # test the case when LANG_FILES is a list lang_files_list = ['maude', 'bunny', 'uli'] _lazy(trans_str, lang_files=lang_files_list).__unicode__() call_lang_files = lang_files_list + settings.DOTLANG_FILES trans_patch.assert_called_with(trans_str, call_lang_files)
def __init__(self, *args, **kwargs): interest_set = kwargs.pop("interest_set", "standard") interest_choices = self.interests_fx if (interest_set == "fx") else self.interests_standard super(WebToLeadForm, self).__init__(*args, **kwargs) self.fields["interest"] = forms.MultipleChoiceField( choices=interest_choices, required=False, widget=forms.SelectMultiple(attrs={"title": _lazy(u"Interest"), "size": 7}), )
def __init__(self, newsletters, locale, data=None, *args, **kwargs): regions = product_details.get_regions(locale) regions = sorted(regions.iteritems(), key=itemgetter(1)) newsletters = validate_newsletters(newsletters) if data and 'newsletters' not in data: data['newsletters'] = newsletters lang = locale.lower() if '-' in lang: lang, country = lang.split('-', 1) else: country = '' regions.insert(0, ('', _lazy('Select country'))) lang_choices = get_lang_choices(newsletters) languages = [x[0] for x in lang_choices] if lang not in languages: # The lang from their locale is not one that our newsletters # are translated into. Initialize the language field to no # choice, to force the user to pick one of the languages that # we do support. lang = '' lang_choices.insert(0, ('', _lazy('Available Languages'))) super(NewsletterFooterForm, self).__init__(data, *args, **kwargs) required_args = { 'required': 'required', 'aria-required': 'true', } country_widget = widgets.Select(attrs=required_args) self.fields['country'] = forms.ChoiceField(widget=country_widget, choices=regions, initial=country, required=False) lang_widget = widgets.Select(attrs=required_args) self.fields['lang'] = forms.TypedChoiceField(widget=lang_widget, choices=lang_choices, initial=lang, required=False) self.fields['newsletters'].initial = newsletters
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)
def __init__(self, newsletters, locale, *args, **kwargs): regions = product_details.get_regions(locale) regions = sorted(regions.iteritems(), key=itemgetter(1)) self.newsletters = newsletters.replace(' ', '') lang = locale.lower() if '-' in lang: lang, country = lang.split('-', 1) else: country = '' regions.insert(0, ('', _lazy('Select country'))) lang_choices = get_lang_choices(self.newsletters) languages = [x[0] for x in lang_choices] if lang not in languages: # The lang from their locale is not one that our newsletters # are translated into. Initialize the language field to no # choice, to force the user to pick one of the languages that # we do support. lang = '' lang_choices.insert(0, ('', _lazy('Available Languages'))) super(NewsletterFooterForm, self).__init__(*args, **kwargs) required_args = { 'required': 'required', 'aria-required': 'true', } country_widget = widgets.Select(attrs=required_args) self.fields['country'] = forms.ChoiceField(widget=country_widget, choices=regions, initial=country, required=False) lang_widget = widgets.Select(attrs=required_args) self.fields['lang'] = forms.TypedChoiceField(widget=lang_widget, choices=lang_choices, initial=lang, required=False)
def __init__(self, *args, **kwargs): interest_set = kwargs.pop('interest_set', 'standard') interest_choices = self.interests_fx if ( interest_set == 'fx') else self.interests_standard super(WebToLeadForm, self).__init__(*args, **kwargs) self.fields['interest'] = forms.MultipleChoiceField( choices=interest_choices, required=False, widget=forms.SelectMultiple(attrs={ 'title': _lazy(u'Interest'), 'size': 7 }))
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)
def __init__(self, *args, **kwargs): interest_set = kwargs.pop('interest_set', 'standard') interest_choices = self.interests_fx if (interest_set == 'fx') else self.interests_standard super(WebToLeadForm, self).__init__(*args, **kwargs) self.fields['interest'] = forms.MultipleChoiceField( choices=interest_choices, required=False, widget=forms.SelectMultiple( attrs={ 'title': _lazy(u'Interest'), 'size': 7 } ) )
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 # If data['lang'] is set, pass it to the template. # If it's None, empty, or nonexistent, pass 'en'. request.newsletter_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'], data['newsletter'], **kwargs) except basket.BasketException: log.exception("Error subscribing %s to newsletter %s" % (data['email'], data['newsletter'])) 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_form = form request.newsletter_success = success
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 # If data['lang'] is set, pass it to the template. # If it's None, empty, or nonexistent, pass 'en'. request.newsletter_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'], data['newsletter'], **kwargs) except basket.BasketException: log.exception("Error subscribing %s to newsletter %s" % (data['email'], data['newsletter'])) 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_form = form request.newsletter_success = success
class FraudReportForm(forms.Form): input_url = forms.URLField( max_length=2000, required=True, error_messages={ 'required': _lazy(u'Please enter a URL.'), }, widget=forms.TextInput( attrs={ 'size': 40, 'placeholder': _lazy(u'http://offendingsite.com'), 'class': 'required fill-width', 'required': 'required', 'aria-required': 'true', } ) ) input_category = forms.ChoiceField( choices=( ('Charging for software', _lazy(u'Charging for software')), ('Collecting personal information', _lazy(u'Collecting personal information')), ('Domain name violation', _lazy(u'Domain name violation')), ('Logo misuse/modification', _lazy(u'Logo misuse/modification')), ('Distributing modified Firefox/malware', _lazy(u'Distributing modified Firefox/malware')), ), required=True, error_messages={ 'required': _lazy('Please select a category.'), }, widget=forms.Select( attrs={ 'title': _lazy(u'Category'), 'class': 'required', 'required': 'required', 'aria-required': 'true', } ) ) input_product = forms.ChoiceField( choices=( ('Firefox', _lazy(u'Firefox')), ('SeaMonkey', _lazy(u'SeaMonkey')), ('Thunderbird', _lazy(u'Thunderbird')), ('Other Mozilla Product/Project', _lazy(u'Other Mozilla Product/Project (specify)')), ), required=True, error_messages={ 'required': _lazy('Please select a product.'), }, widget=forms.Select( attrs={ 'title': _lazy(u'Product'), 'class': 'required', 'required': 'required', 'aria-required': 'true', } ) ) input_specific_product = forms.CharField( max_length=254, required=False, widget=forms.TextInput( attrs={ 'size': 20, 'class': 'fill-width' } ) ) input_details = forms.CharField( required=False, widget=forms.Textarea( attrs={ 'rows': '', 'cols': '', 'class': 'fill-width' } ) ) input_attachment = forms.FileField( required=False, ) input_attachment_desc = forms.CharField( max_length=254, required=False, widget=forms.Textarea( attrs={ 'rows': '', 'cols': '', 'class': 'fill-width' } ) ) input_email = forms.EmailField( max_length=254, required=False, error_messages={ 'invalid': _lazy(u'Please enter a valid email address'), }, widget=forms.TextInput( attrs={ 'size': 20, 'class': 'fill-width' } ) ) superpriority = forms.BooleanField(widget=HoneyPotWidget, required=False) def clean_input_attachment(self): cleaned_data = super(FraudReportForm, self).clean() attachment = cleaned_data.get("input_attachment") if attachment: if attachment._size > FRAUD_REPORT_FILE_SIZE_LIMIT: raise forms.ValidationError( _("Attachment must not exceed 5MB")) return attachment def clean_superpriority(self): cleaned_data = super(FraudReportForm, self).clean() honeypot = cleaned_data.pop('superpriority', None) if honeypot: raise forms.ValidationError( _('Your submission could not be processed'))
import requests from lib.l10n_utils.dotlang import _, _lazy from commonware.decorators import xframe_allow from funfactory.urlresolvers import reverse from .forms import (EmailForm, ManageSubscriptionsForm, NewsletterForm, NewsletterFooterForm) # Cannot use short "from . import utils" because we need to mock # utils.get_newsletters in our tests from bedrock.mozorg.util import HttpResponseJSON from bedrock.newsletter import utils log = commonware.log.getLogger('b.newsletter') LANG_FILES = ['mozorg/contribute'] general_error = _lazy(u'We are sorry, but there was a problem ' u'with our system. Please try again later!') thank_you = _lazy(u'Thanks for updating your email preferences.') bad_token = _lazy(u'The supplied link has expired or is not valid. You will ' u'receive a new one in the next newsletter, or below you ' u'can request an email with the link.') recovery_text = _lazy( u'Success! An email has been sent to you with your preference center ' u'link. Thanks!') # NOTE: Must format a link into this: (https://www.mozilla.org/newsletter/) unknown_address_text = _lazy( u'This email address is not in our system. Please double check your ' u'address or <a href="%s">subscribe to our newsletters.</a>') invalid_email_address = _lazy(u'This is not a valid email address. ' u'Please check the spelling.')
import lib.l10n_utils as l10n_utils import requests from lib.l10n_utils.dotlang import _lazy from commonware.decorators import xframe_allow from funfactory.urlresolvers import reverse from .forms import (EmailForm, ManageSubscriptionsForm, NewsletterForm, NewsletterFooterForm) # Cannot use short "from . import utils" because we need to mock # utils.get_newsletters in our tests from bedrock.newsletter import utils log = commonware.log.getLogger('b.newsletter') LANG_FILES = ['mozorg/contribute'] general_error = _lazy(u'We are sorry, but there was a problem ' u'with our system. Please try again later!') thank_you = _lazy(u'Thank you for updating your email preferences.') bad_token = _lazy(u'The supplied link has expired or is not valid. You will ' u'receive a new one in the next newsletter, or below you ' u'can request an email with the link.') recovery_text = _lazy( u'Success! An email has been sent to you with your preference center ' u'link. Thanks!') # NOTE: Must format a link into this: (https://www.mozilla.org/newsletter/) unknown_address_text = _lazy( u'This email address is not in our system. Please double check your ' u'address or <a href="%s">subscribe to our newsletters.</a>') UNSUB_UNSUBSCRIBED_ALL = 1 UNSUB_REASONS_SUBMITTED = 2
from django import forms from django.forms import widgets from django.utils.safestring import mark_safe from django.core.urlresolvers import reverse import basket from basket.base import request from lib.l10n_utils.dotlang import _ from lib.l10n_utils.dotlang import _lazy from product_details import product_details from .email_contribute import INTEREST_CHOICES FORMATS = (("H", _lazy("HTML")), ("T", _lazy("Text"))) LANGS_TO_STRIP = ["en-US", "es"] PARENTHETIC_RE = re.compile(r" \([^)]+\)$") LANG_FILES = ["firefox/partners/index", "mozorg/contribute", "mozorg/contribute/index"] def strip_parenthetical(lang_name): """ Remove the parenthetical from the end of the language name string. """ return PARENTHETIC_RE.sub("", lang_name, 1) class SideRadios(widgets.RadioFieldRenderer): """Render radio buttons as labels"""
class SpeakerRequestForm(forms.Form): # event fields sr_event_name = forms.CharField( max_length=255, required=True, error_messages={ "required": _lazy("Please enter a name for the event."), }, widget=forms.TextInput( attrs={ "class": "required", "required": "required", "aria-required": "true", } ), ) sr_event_url = forms.URLField( max_length=2000, required=True, error_messages={ "required": _lazy("Please enter a URL."), "invalid": _lazy("Please enter a valid URL."), }, widget=URLInput( attrs={ "class": "required", "required": "required", "aria-required": "true", "placeholder": _lazy("http://www.my-event.com"), } ), ) sr_event_date = forms.CharField( required=True, error_messages={ "required": _lazy("Please provide a date."), }, widget=DateInput( attrs={ "class": "required", "required": "required", "aria-required": "true", } ), ) sr_event_time = forms.CharField( required=True, error_messages={ "required": _lazy("Please provide a time."), }, widget=TimeInput( attrs={ "class": "required", "required": "required", "aria-required": "true", } ), ) sr_guest_speaker1 = forms.CharField( max_length=200, required=False, ) sr_guest_speaker2 = forms.CharField( max_length=200, required=False, ) # contact fields sr_contact_name = forms.CharField( max_length=200, required=True, widget=forms.TextInput( attrs={ "required": "required", "class": "required", "aria-required": "true", } ), ) sr_contact_title = forms.CharField( max_length=200, required=False, ) sr_contact_company = forms.CharField( max_length=200, required=False, ) sr_contact_phone = forms.CharField( max_length=50, required=False, widget=TelInput(), ) sr_contact_email = forms.EmailField( max_length=254, # max length allowed for emails required=True, error_messages={ "invalid": _lazy("Please enter a valid email address"), }, widget=EmailInput( attrs={ "required": "required", "class": "required", "aria-required": "true", } ), ) sr_contact_company_url = forms.URLField( max_length=2000, required=False, widget=forms.TextInput( attrs={ "placeholder": _lazy("http://www.my-company.com"), } ), ) # event details fields sr_event_venue = forms.CharField( max_length=400, required=False, ) sr_event_theme = forms.CharField( max_length=200, required=False, ) sr_event_goal = forms.CharField( max_length=300, required=False, ) sr_event_format = forms.CharField( max_length=200, required=False, ) sr_event_audience_size = forms.IntegerField( required=False, widget=NumberInput( attrs={ "min": 1, "placeholder": 25, } ), ) sr_event_audience_demographics = forms.CharField( max_length=500, required=False, widget=forms.Textarea( attrs={ "rows": "", "cols": "", } ), ) sr_event_speakers_confirmed = forms.CharField( max_length=500, required=False, widget=forms.Textarea( attrs={ "rows": "", "cols": "", } ), ) sr_event_speakers_invited = forms.CharField( max_length=500, required=False, widget=forms.Textarea( attrs={ "rows": "", "cols": "", } ), ) sr_event_speakers_past = forms.CharField( max_length=1000, required=False, widget=forms.Textarea( attrs={ "rows": "", "cols": "", } ), ) sr_event_media_coverage = forms.CharField( max_length=500, required=False, widget=forms.Textarea( attrs={ "rows": "", "cols": "", } ), ) sr_event_sponsors = forms.CharField( max_length=500, required=False, widget=forms.Textarea( attrs={ "rows": "", "cols": "", } ), ) sr_event_confirmation_deadline = forms.DateField( required=False, widget=DateInput(), ) # presentation details fields sr_presentation_type = forms.MultipleChoiceField( required=False, choices=( ("keynote", _lazy("Keynote")), ("presentation", _lazy("Presentation")), ("fireside chat", _lazy("Fireside Chat")), ("panel", _lazy("Panel")), ("other", _lazy("Other")), ), widget=forms.CheckboxSelectMultiple(), ) sr_presentation_panelists = forms.CharField( max_length=500, required=False, widget=forms.Textarea(), ) sr_presentation_topic = forms.CharField( required=False, max_length=255, ) sr_presentation_length = forms.IntegerField( required=False, widget=NumberInput( attrs={ "min": 0.5, "step": 0.5, "placeholder": 2.5, } ), ) # additional info fields sr_attachment = forms.FileField( required=False, ) # honeypot office_fax = forms.CharField(widget=HoneyPotWidget, required=False) def clean_sr_attachment(self): cleaned_data = super().clean() attachment = cleaned_data.get("sr_attachment") if attachment: if attachment.size > SPEAKER_REQUEST_FILE_SIZE_LIMIT: raise forms.ValidationError(_("Attachment must not exceed 5MB")) return attachment def clean_office_fax(self): cleaned_data = super().clean() honeypot = cleaned_data.pop("office_fax", None) if honeypot: raise forms.ValidationError(_("Your submission could not be processed"))
import requests from lib.l10n_utils.dotlang import _, _lazy from commonware.decorators import xframe_allow from bedrock.base.urlresolvers import reverse from .forms import (EmailForm, ManageSubscriptionsForm, NewsletterForm, NewsletterFooterForm) # Cannot use short "from . import utils" because we need to mock # utils.get_newsletters in our tests from bedrock.mozorg.util import HttpResponseJSON from bedrock.newsletter import utils log = commonware.log.getLogger('b.newsletter') LANG_FILES = ['mozorg/newsletters'] general_error = _lazy(u'We are sorry, but there was a problem ' u'with our system. Please try again later!') thank_you = _lazy(u'Thanks for updating your email preferences.') bad_token = _lazy(u'The supplied link has expired or is not valid. You will ' u'receive a new one in the next newsletter, or below you ' u'can request an email with the link.') recovery_text = _lazy( u'Success! An email has been sent to you with your preference center ' u'link. Thanks!') # NOTE: Must format a link into this: (https://www.mozilla.org/newsletter/) unknown_address_text = _lazy( u'This email address is not in our system. Please double check your ' u'address or <a href="%s">subscribe to our newsletters.</a>') invalid_email_address = _lazy(u'This is not a valid email address. ' u'Please check the spelling.')
class WebToLeadForm(forms.Form): interests_standard = ( ('Firefox for Desktop', _lazy(u'Firefox for Desktop')), ('Firefox for Android', _lazy(u'Firefox for Android')), ('Firefox Marketplace', _lazy(u'Firefox Marketplace')), ('Firefox OS', _lazy(u'Firefox OS')), ('Persona', _lazy(u'Persona')), ('Marketing and Co-promotions', _lazy(u'Marketing and Co-promotions')), ('Other', _lazy(u'Other')), ) interests_fx = ( ('Firefox for Android', _lazy(u'Firefox for Android')), ('Firefox Marketplace', _lazy(u'Firefox Marketplace')), ('Firefox OS', _lazy(u'Firefox OS')), ('Other', _lazy(u'Other')), ) first_name = forms.CharField( max_length=40, required=True, error_messages={ 'required': _lazy(u'Please enter your first name.') }, widget=forms.TextInput( attrs={ 'size': 20, 'placeholder': _lazy(u'First Name'), 'class': 'required', 'required': 'required', 'aria-required': 'true' } ) ) last_name = forms.CharField( max_length=80, required=True, error_messages={ 'required': _('Please enter your last name.') }, widget=forms.TextInput( attrs={ 'size': 20, 'placeholder': _lazy(u'Last Name'), 'class': 'required', 'required': 'required', 'aria-required': 'true' } ) ) title = forms.CharField( max_length=40, required=False, widget=forms.TextInput( attrs={ 'size': 20, 'placeholder': _lazy(u'Title') } ) ) company = forms.CharField( max_length=40, required=True, error_messages={ 'required': _lazy(u'Please enter your company name.') }, widget=forms.TextInput( attrs={ 'size': 20, 'placeholder': _lazy(u'Company'), 'class': 'required', 'required': 'required', 'aria-required': 'true' } ) ) URL = forms.URLField( max_length=80, required=False, error_messages={ 'invalid': _lazy(u'Please supply a valid URL.') }, widget=forms.TextInput( attrs={ 'size': 20, 'placeholder': _lazy(u'Website') } ) ) email = forms.EmailField( max_length=80, required=True, error_messages={ 'required': _lazy(u'Please enter your email address.'), 'invalid': _lazy(u'Please enter a valid email address') }, widget=forms.TextInput( attrs={ 'size': 20, 'placeholder': _lazy(u'Email'), 'class': 'required', 'required': 'required', 'aria-required': 'true' } ) ) phone = forms.CharField( max_length=40, required=False, widget=forms.TextInput( attrs={ 'size': 20, 'placeholder': _lazy(u'Phone') } ) ) mobile = forms.CharField( max_length=40, required=False, widget=forms.TextInput( attrs={ 'size': 20, 'placeholder': _lazy(u'Mobile') } ) ) street = forms.CharField( required=False, widget=forms.Textarea( attrs={ 'placeholder': _lazy(u'Address'), 'rows': '', 'cols': '' } ) ) city = forms.CharField( required=False, max_length=40, widget=forms.TextInput( attrs={ 'placeholder': _lazy(u'City') } ) ) state = forms.CharField( required=False, max_length=40, widget=forms.TextInput( attrs={ 'placeholder': _lazy(u'State/Province') } ) ) country = forms.CharField( required=False, max_length=40, widget=forms.TextInput( attrs={ 'placeholder': _lazy(u'Country') } ) ) zip = forms.CharField( required=False, max_length=40, widget=forms.TextInput( attrs={ 'placeholder': _lazy(u'Zip') } ) ) description = forms.CharField( required=False, widget=forms.Textarea( attrs={ 'placeholder': _lazy(u'Description'), 'rows': '', 'cols': '' } ) ) superpriority = forms.BooleanField(widget=HoneyPotWidget, required=False) # uncomment below to debug salesforce # debug = forms.IntegerField(required=False) # debugEmail = forms.EmailField(required=False) def __init__(self, *args, **kwargs): interest_set = kwargs.pop('interest_set', 'standard') interest_choices = self.interests_fx if (interest_set == 'fx') else self.interests_standard kwargs.pop('lead_source', None) super(WebToLeadForm, self).__init__(*args, **kwargs) self.fields['interest'] = forms.MultipleChoiceField( choices=interest_choices, required=False, widget=forms.SelectMultiple( attrs={ 'title': _lazy(u'Interest'), 'size': 7 } ) )
class FraudReportForm(forms.Form): input_url = forms.URLField( max_length=2000, required=True, error_messages={ "required": _lazy("Please enter a URL."), }, widget=forms.TextInput( attrs={ "size": 40, "placeholder": _lazy("http://offendingsite.com"), "class": "required fill-width", "required": "required", "aria-required": "true", }), ) input_category = forms.ChoiceField( choices=( ("Charging for software", _lazy("Charging for software")), ("Collecting personal information", _lazy("Collecting personal information")), ("Domain name violation", _lazy("Domain name violation")), ("Logo misuse/modification", _lazy("Logo misuse/modification")), ("Distributing modified Firefox/malware", _lazy("Distributing modified Firefox/malware")), ), required=True, error_messages={ "required": _lazy("Please select a category."), }, widget=forms.Select( attrs={ "title": _lazy("Category"), "class": "required", "required": "required", "aria-required": "true", }), ) input_product = forms.ChoiceField( choices=( ("Firefox", _lazy("Firefox")), ("SeaMonkey", _lazy("SeaMonkey")), ("Thunderbird", _lazy("Thunderbird")), ("Other Mozilla Product/Project", _lazy("Other Mozilla Product/Project (specify)")), ), required=True, error_messages={ "required": _lazy("Please select a product."), }, widget=forms.Select( attrs={ "title": _lazy("Product"), "class": "required", "required": "required", "aria-required": "true", }), ) input_specific_product = forms.CharField( max_length=254, required=False, widget=forms.TextInput(attrs={ "size": 20, "class": "fill-width" })) input_details = forms.CharField( required=False, widget=forms.Textarea(attrs={ "rows": "", "cols": "", "class": "fill-width" })) input_attachment = forms.ImageField(required=False) input_attachment_desc = forms.CharField( max_length=254, required=False, widget=forms.Textarea(attrs={ "rows": "", "cols": "", "class": "fill-width" })) input_email = forms.EmailField( max_length=254, required=False, error_messages={ "invalid": _lazy("Please enter a valid email address"), }, widget=forms.TextInput(attrs={ "size": 20, "class": "fill-width" }), ) # honeypot office_fax = forms.CharField(widget=HoneyPotWidget, required=False) def clean_input_attachment(self): attachment = self.cleaned_data.get("input_attachment") if attachment: if attachment.size > FRAUD_REPORT_FILE_SIZE_LIMIT: raise forms.ValidationError( _("Attachment must not exceed 5MB")) return attachment def clean_office_fax(self): honeypot = self.cleaned_data.pop("office_fax", None) if honeypot: raise forms.ValidationError( _("Your submission could not be processed"))
from django import forms from django.forms import widgets from django.utils.safestring import mark_safe from django.core.urlresolvers import reverse import basket from basket.base import request from lib.l10n_utils.dotlang import _ from lib.l10n_utils.dotlang import _lazy from product_details import product_details from .email_contribute import INTEREST_CHOICES FORMATS = (('H', _lazy('HTML')), ('T', _lazy('Text'))) LANGS_TO_STRIP = ['en-US', 'es'] PARENTHETIC_RE = re.compile(r' \([^)]+\)$') LANG_FILES = ['mozorg/contribute', 'firefox/partners/index'] def strip_parenthetical(lang_name): """ Remove the parenthetical from the end of the language name string. """ return PARENTHETIC_RE.sub('', lang_name, 1) class SideRadios(widgets.RadioFieldRenderer): """Render radio buttons as labels"""
class WebToLeadForm(forms.Form): interests_standard = ( ('Firefox for Desktop', _lazy(u'Firefox for Desktop')), ('Firefox for Android', _lazy(u'Firefox for Android')), ('Firefox Marketplace', _lazy(u'Firefox Marketplace')), ('Marketing and Co-promotions', _lazy(u'Marketing and Co-promotions')), ('Other', _lazy(u'Other')), ) interests_fx = ( ('Firefox for Android', _lazy(u'Firefox for Android')), ('Firefox Marketplace', _lazy(u'Firefox Marketplace')), ('Other', _lazy(u'Other')), ) industries = ( ('', 'Select Industry'), ('Agriculture', _lazy(u'Agriculture')), ('Apparel', _lazy(u'Apparel')), ('Banking', _lazy(u'Banking')), ('Biotechnology', _lazy(u'Biotechnology')), ('Chemicals', _lazy(u'Chemicals')), ('Communications', _lazy(u'Communications')), ('Construction', _lazy(u'Construction')), ('Consulting', _lazy(u'Consulting')), ('Education', _lazy(u'Education')), ('Electronics', _lazy(u'Electronics')), ('Energy', _lazy(u'Energy')), ('Engineering', _lazy(u'Engineering')), ('Entertainment', _lazy(u'Entertainment')), ('Environmental', _lazy(u'Environmental')), ('Finance', _lazy(u'Finance')), ('Food & Beverage', _lazy(u'Food & Beverage')), ('Government', _lazy(u'Government')), ('Healthcare', _lazy(u'Healthcare')), ('Hospitality', _lazy(u'Hospitality')), ('Insurance', _lazy(u'Insurance')), ('Machinery', _lazy(u'Machinery')), ('Manufacturing', _lazy(u'Manufacturing')), ('Media', _lazy(u'Media')), ('Not For Profit', _lazy(u'Not For Profit')), ('Other', _lazy(u'Other')), ('Recreation', _lazy(u'Recreation')), ('Retail', _lazy(u'Retail')), ('Shipping', _lazy(u'Shipping')), ('Technology', _lazy(u'Technology')), ('Telecommunications', _lazy(u'Telecommunications')), ('Transportation', _lazy(u'Transportation')), ('Utilities', _lazy(u'Utilities')), ) first_name = forms.CharField( max_length=40, required=True, error_messages={'required': _lazy(u'Please enter your first name.')}, widget=forms.TextInput( attrs={ 'size': 20, 'placeholder': _lazy(u'First Name'), 'class': 'required', 'required': 'required', 'aria-required': 'true' })) last_name = forms.CharField( max_length=80, required=True, error_messages={'required': _('Please enter your last name.')}, widget=forms.TextInput( attrs={ 'size': 20, 'placeholder': _lazy(u'Last Name'), 'class': 'required', 'required': 'required', 'aria-required': 'true' })) title = forms.CharField( max_length=40, required=False, widget=forms.TextInput(attrs={ 'size': 20, 'placeholder': _lazy(u'Title') })) company = forms.CharField( max_length=40, required=True, error_messages={'required': _lazy(u'Please enter your company name.')}, widget=forms.TextInput( attrs={ 'size': 20, 'placeholder': _lazy(u'Company'), 'class': 'required', 'required': 'required', 'aria-required': 'true' })) URL = forms.URLField( max_length=80, required=False, error_messages={'invalid': _lazy(u'Please supply a valid URL.')}, widget=forms.TextInput(attrs={ 'size': 20, 'placeholder': _lazy(u'Website') })) email = forms.EmailField(max_length=80, required=True, error_messages={ 'required': _lazy(u'Please enter your email address.'), 'invalid': _lazy(u'Please enter a valid email address') }, widget=forms.TextInput( attrs={ 'size': 20, 'placeholder': _lazy(u'Email'), 'class': 'required', 'required': 'required', 'aria-required': 'true' })) phone = forms.CharField( max_length=40, required=False, widget=forms.TextInput(attrs={ 'size': 20, 'placeholder': _lazy(u'Phone') })) mobile = forms.CharField( max_length=40, required=False, widget=forms.TextInput(attrs={ 'size': 20, 'placeholder': _lazy(u'Mobile') })) street = forms.CharField( required=False, widget=forms.Textarea(attrs={ 'placeholder': _lazy(u'Address'), 'rows': '', 'cols': '' })) city = forms.CharField( required=False, max_length=40, widget=forms.TextInput(attrs={'placeholder': _lazy(u'City')})) state = forms.CharField( required=False, max_length=40, widget=forms.TextInput( attrs={'placeholder': _lazy(u'State/Province')})) country = forms.CharField( required=False, max_length=40, widget=forms.TextInput(attrs={'placeholder': _lazy(u'Country')})) zip = forms.CharField( required=False, max_length=40, widget=forms.TextInput(attrs={'placeholder': _lazy(u'Zip')})) description = forms.CharField( required=False, widget=forms.Textarea(attrs={ 'placeholder': _lazy(u'Description'), 'rows': '', 'cols': '' })) interested_countries = forms.CharField( required=False, widget=forms.Textarea(attrs={ 'placeholder': _lazy(u'Countries of Interest'), 'rows': '', 'cols': '' })) interested_languages = forms.CharField( required=False, widget=forms.Textarea(attrs={ 'placeholder': _lazy(u'Languages of Interest'), 'rows': '', 'cols': '' })) industry = forms.ChoiceField(choices=industries, required=False, widget=forms.Select(attrs={ 'title': _lazy('Industry'), 'size': 1 })) campaign_type = forms.ChoiceField( choices=(('', _lazy(u'Select Campaign Type')), ('Brand', _lazy(u'Brand')), ('Direct Response', _lazy(u'Direct Response'))), required=False, widget=forms.Select(attrs={'title': _lazy('Campaign Type')})) # honeypot office_fax = forms.CharField(widget=HoneyPotWidget, required=False) # uncomment below to debug salesforce # debug = forms.IntegerField(required=False) # debugEmail = forms.EmailField(required=False) def __init__(self, *args, **kwargs): interest_set = kwargs.pop('interest_set', 'standard') interest_choices = self.interests_fx if ( interest_set == 'fx') else self.interests_standard kwargs.pop('lead_source', None) super(WebToLeadForm, self).__init__(*args, **kwargs) self.fields['interest'] = forms.MultipleChoiceField( choices=interest_choices, required=False, widget=forms.SelectMultiple(attrs={ 'title': _lazy(u'Interest'), 'size': 8 }))
class ContributeStudentAmbassadorForm(forms.Form): first_name = forms.CharField(max_length=50) last_name = forms.CharField(max_length=50) email = forms.EmailField(max_length=100) status = forms.ChoiceField(choices=(('', ''), ('student', _lazy('Student')), ('teacher', _lazy('Teacher')), ('administrator', _lazy('Administrator')), ('other', _lazy('Other')))) school = forms.CharField(max_length=100) grad_year = forms.ChoiceField( required=False, choices=([('', _lazy('Expected Graduation Year'))] + [(i, str(i)) for i in range(datetime.now().year, datetime.now().year + 8)])) major = forms.ChoiceField( required=False, choices=[('', ''), ('computer science', _lazy('Computer Science')), ('computer engineering', _lazy('Computer Engineering')), ('engineering', _lazy('Engineering (other)')), ('social science', _lazy('Social Science')), ('science', _lazy('Science (other)')), ('business/marketing', _lazy('Business/Marketing')), ('education', _lazy('Education')), ('mathematics', _lazy('Mathematics')), ('other', _lazy('Other'))]) major_free_text = forms.CharField(max_length=100, required=False) city = forms.CharField(max_length=100) country = forms.ChoiceField() fmt = forms.ChoiceField(widget=forms.RadioSelect(renderer=SideRadios), label=_lazy('Email format preference:'), choices=FORMATS, initial='H') age_confirmation = forms.BooleanField( widget=widgets.CheckboxInput(), label=_lazy(u'I’m 18 years old and eligible to participate in ' 'the program')) share_information = forms.BooleanField( required=False, widget=widgets.CheckboxInput(), label=_lazy(u'Please share my contact information and interests with ' 'related Mozilla contributors for the purpose of ' 'collaborating on Mozilla projects')) privacy = forms.BooleanField(widget=PrivacyWidget) nl_mozilla_and_you = forms.BooleanField( required=False, widget=widgets.CheckboxInput(), label=_lazy(u'Firefox & You: A monthly newsletter packed with tips to' ' improve your browsing experience')) nl_about_mozilla = forms.BooleanField( required=False, widget=widgets.CheckboxInput(), label=_lazy(u'About Mozilla: News from the Mozilla Project')) # honeypot office_fax = forms.CharField(widget=HoneyPotWidget, required=False) source_url = forms.URLField(required=False) def __init__(self, *args, **kwargs): locale = kwargs.get('locale', 'en-US') super(ContributeStudentAmbassadorForm, self).__init__(*args, **kwargs) country_list = product_details.get_regions(locale).items() country_list = sorted(country_list, key=lambda country: country[1]) country_list.insert(0, ('', '')) self.fields['country'].choices = country_list def clean(self, *args, **kwargs): super(ContributeStudentAmbassadorForm, self).clean(*args, **kwargs) if (self.cleaned_data.get('status', '') == 'student' and not self.cleaned_data.get('grad_year', '')): self._errors['grad_year'] = (self.error_class( [_('This field is required.')])) return self.cleaned_data def clean_grad_year(self): return self.cleaned_data.get('grad_year', '') def clean_major(self): return self.cleaned_data.get('major_free_field', self.cleaned_data['major']) def clean_share_information(self): if self.cleaned_data.get('share_information', False): return 'Y' return 'N' def clean_office_fax(self): honeypot = self.cleaned_data.pop('office_fax', None) if honeypot: raise forms.ValidationError( _('Your submission could not be processed')) def newsletters(self): newsletters = ['ambassadors'] for newsletter in ['nl_mozilla_and_you', 'nl_about_mozilla']: if self.cleaned_data.get(newsletter, False): newsletters.append(newsletter[3:].replace('_', '-')) return newsletters def save(self): data = self.cleaned_data result = basket.subscribe( data['email'], self.newsletters(), format=data['fmt'], country=data['country'], welcome_message='Student_Ambassadors_Welcome', source_url=data['source_url'], sync='Y') data = { 'FIRST_NAME': data['first_name'], 'LAST_NAME': data['last_name'], 'STUDENTS_CURRENT_STATUS': data['status'], 'STUDENTS_SCHOOL': data['school'], 'STUDENTS_GRAD_YEAR': data['grad_year'], 'STUDENTS_MAJOR': data['major'], 'COUNTRY_': data['country'], 'STUDENTS_CITY': data['city'], 'STUDENTS_ALLOW_SHARE': data['share_information'], } request('post', 'custom_update_student_ambassadors', token=result['token'], data=data)
class SpeakerRequestForm(forms.Form): # event fields sr_event_name = forms.CharField( max_length=255, required=True, error_messages={ 'required': _lazy(u'Please enter a name for the event.'), }, widget=forms.TextInput(attrs={ 'class': 'required', 'required': 'required', 'aria-required': 'true', }), ) sr_event_url = forms.URLField( max_length=2000, required=True, error_messages={ 'required': _lazy(u'Please enter a URL.'), 'invalid': _lazy(u'Please enter a valid URL.'), }, widget=URLInput( attrs={ 'class': 'required', 'required': 'required', 'aria-required': 'true', 'placeholder': _lazy(u'http://www.my-event.com'), }), ) sr_event_date = forms.CharField( required=True, error_messages={ 'required': _lazy(u'Please provide a date.'), }, widget=DateInput(attrs={ 'class': 'required', 'required': 'required', 'aria-required': 'true', }), ) sr_event_time = forms.CharField( required=True, error_messages={ 'required': _lazy(u'Please provide a time.'), }, widget=TimeInput(attrs={ 'class': 'required', 'required': 'required', 'aria-required': 'true', }), ) sr_guest_speaker1 = forms.CharField( max_length=200, required=False, ) sr_guest_speaker2 = forms.CharField( max_length=200, required=False, ) # contact fields sr_contact_name = forms.CharField( max_length=200, required=True, widget=forms.TextInput(attrs={ 'required': 'required', 'class': 'required', 'aria-required': 'true', }), ) sr_contact_title = forms.CharField( max_length=200, required=False, ) sr_contact_company = forms.CharField( max_length=200, required=False, ) sr_contact_phone = forms.CharField( max_length=50, required=False, widget=TelInput(), ) sr_contact_email = forms.EmailField( max_length=254, # max length allowed for emails required=True, error_messages={ 'invalid': _lazy(u'Please enter a valid email address'), }, widget=EmailInput(attrs={ 'required': 'required', 'class': 'required', 'aria-required': 'true', }), ) sr_contact_company_url = forms.URLField( max_length=2000, required=False, widget=forms.TextInput( attrs={ 'placeholder': _lazy(u'http://www.my-company.com'), }), ) # event details fields sr_event_venue = forms.CharField( max_length=400, required=False, ) sr_event_theme = forms.CharField( max_length=200, required=False, ) sr_event_goal = forms.CharField( max_length=300, required=False, ) sr_event_format = forms.CharField( max_length=200, required=False, ) sr_event_audience_size = forms.IntegerField( required=False, widget=NumberInput(attrs={ 'min': 1, 'placeholder': 25, }), ) sr_event_audience_demographics = forms.CharField( max_length=500, required=False, widget=forms.Textarea(), ) sr_event_speakers_confirmed = forms.CharField( max_length=500, required=False, widget=forms.Textarea(), ) sr_event_speakers_invited = forms.CharField( max_length=500, required=False, widget=forms.Textarea(), ) sr_event_speakers_past = forms.CharField( max_length=1000, required=False, widget=forms.Textarea(), ) sr_event_media_coverage = forms.CharField( max_length=500, required=False, widget=forms.Textarea(), ) sr_event_sponsors = forms.CharField( max_length=500, required=False, widget=forms.Textarea(), ) sr_event_confirmation_deadline = forms.DateField( required=False, widget=DateInput(), ) # presentation details fields sr_presentation_type = forms.MultipleChoiceField( required=False, choices=( ('keynote', _lazy(u'Keynote')), ('presentation', _lazy(u'Presentation')), ('fireside chat', _lazy(u'Fireside Chat')), ('panel', _lazy(u'Panel')), ('other', _lazy(u'Other')), ), widget=forms.CheckboxSelectMultiple(), ) sr_presentation_panelists = forms.CharField( max_length=500, required=False, widget=forms.Textarea(), ) sr_presentation_topic = forms.CharField( required=False, max_length=255, ) sr_presentation_length = forms.IntegerField( required=False, widget=NumberInput(attrs={ 'min': 0.5, 'step': 0.5, 'placeholder': 2.5, })) # additional info fields sr_attachment = forms.FileField(required=False, ) # honeypot office_fax = forms.CharField(widget=HoneyPotWidget, required=False) def clean_sr_attachment(self): cleaned_data = super(SpeakerRequestForm, self).clean() attachment = cleaned_data.get("sr_attachment") if attachment: if attachment._size > SPEAKER_REQUEST_FILE_SIZE_LIMIT: raise forms.ValidationError( _("Attachment must not exceed 5MB")) return attachment def clean_office_fax(self): cleaned_data = super(SpeakerRequestForm, self).clean() honeypot = cleaned_data.pop('office_fax', None) if honeypot: raise forms.ValidationError( _('Your submission could not be processed'))
from lib.l10n_utils.dotlang import _lazy from commonware.decorators import xframe_allow from funfactory.urlresolvers import reverse from .forms import ( ManageSubscriptionsForm, NewsletterForm, NewsletterFooterForm) # Cannot use short "from . import utils" because we need to mock # utils.get_newsletters in our tests from bedrock.newsletter import utils log = commonware.log.getLogger('b.newsletter') LANG_FILES = ['mozorg/contribute'] general_error = _lazy(u'We are sorry, but there was a problem ' u'with our system. Please try again later!') thank_you = _lazy(u'Thank you for updating your email preferences.') bad_token = _lazy(u'The supplied link has expired. You will receive a new ' u'one in the next newsletter.') UNSUB_UNSUBSCRIBED_ALL = 1 UNSUB_REASONS_SUBMITTED = 2 @xframe_allow def hacks_newsletter(request): return l10n_utils.render(request, 'newsletter/hacks.mozilla.org.html') @never_cache
class ContributeSignupForm(forms.Form): required_attr = {'required': 'required'} empty_choice = ('', '') category_choices = ( ('coding', _lazy('Coding')), ('testing', _lazy('Testing')), ('writing', _lazy('Writing')), ('teaching', _lazy('Teaching')), ('helping', _lazy('Helping')), ('translating', _lazy('Translating')), ('activism', _lazy('Activism')), ('dontknow', _lazy(u'I don’t know')), ) coding_choices = ( empty_choice, ('coding-firefox', _lazy('Firefox')), ('coding-websites', _lazy('Websites')), ('coding-addons', _lazy('Firefox add-ons')), ('coding-marketplace', _lazy('HTML5 apps')), ('coding-webcompat', _lazy('Diagnosing Web compatibility issues')), ('coding-cloud', _lazy('Online services')), ) testing_choices = ( empty_choice, ('testing-firefox', _lazy('Firefox')), ('testing-addons', _lazy('Firefox add-ons')), ('testing-marketplace', _lazy('HTML5 apps')), ('testing-websites', _lazy('Websites')), ('testing-webcompat', _lazy('Web compatibility')), ) translating_choices = ( empty_choice, ('translating-products', _lazy('Products')), ('translating-websites', _lazy('Websites')), ('translating-tools', _lazy(u'I’d like to work on localization tools')), ) writing_choices = ( empty_choice, ('writing-journalism', _lazy('Journalism')), ('writing-techusers', _lazy('Technical docs for users')), ('writing-techdevs', _lazy('Technical docs for developers')), ('writing-addons', _lazy('Technical docs for Firefox add-ons')), ('writing-marketplace', _lazy('Technical docs for HTML5 apps')), ) teaching_choices = ( empty_choice, ('teaching-webmaker', _lazy('Teach the Web (Webmaker)')), ('teaching-fellowships', _lazy('Open News fellowships')), ('teaching-hive', _lazy('Hive - Community networks of educators/mentors')), ('teaching-science', _lazy('Open Web science research')), ) email = forms.EmailField(widget=EmailInput(attrs=required_attr)) privacy = forms.BooleanField(widget=PrivacyWidget) category = forms.ChoiceField(choices=category_choices, widget=forms.RadioSelect(attrs=required_attr)) area_coding = forms.ChoiceField(choices=coding_choices, required=False, widget=L10nSelect) area_testing = forms.ChoiceField(choices=testing_choices, required=False, widget=L10nSelect) area_translating = forms.ChoiceField(choices=translating_choices, required=False, widget=L10nSelect) area_writing = forms.ChoiceField(choices=writing_choices, required=False, widget=L10nSelect) area_teaching = forms.ChoiceField(choices=teaching_choices, required=False, widget=L10nSelect) name = forms.CharField(widget=forms.TextInput(attrs=required_attr)) message = forms.CharField(widget=forms.Textarea, required=False) newsletter = forms.BooleanField(required=False) format = forms.ChoiceField(widget=forms.RadioSelect(attrs=required_attr), choices=( ('H', _lazy('HTML')), ('T', _lazy('Text')), )) def __init__(self, locale, *args, **kwargs): regions = product_details.get_regions(locale) regions = sorted(regions.iteritems(), key=itemgetter(1)) regions.insert(0, self.empty_choice) super(ContributeSignupForm, self).__init__(*args, **kwargs) self.locale = locale self.fields['country'] = forms.ChoiceField( choices=regions, widget=L10nSelect(attrs={'required': 'required'})) def clean(self): cleaned_data = super(ContributeSignupForm, self).clean() category = cleaned_data.get('category') # only bother if category was supplied if category: area_name = 'area_' + category if area_name in cleaned_data and not cleaned_data[area_name]: required_message = self.fields[area_name].error_messages[ 'required'] self._errors[area_name] = self.error_class([required_message]) del cleaned_data[area_name] return cleaned_data
class ContentServicesForm(forms.Form): industries = ( ('', 'Select Industry'), ('Agriculture', _lazy(u'Agriculture')), ('Apparel', _lazy(u'Apparel')), ('Banking', _lazy(u'Banking')), ('Biotechnology', _lazy(u'Biotechnology')), ('Chemicals', _lazy(u'Chemicals')), ('Communications', _lazy(u'Communications')), ('Construction', _lazy(u'Construction')), ('Consulting', _lazy(u'Consulting')), ('Education', _lazy(u'Education')), ('Electronics', _lazy(u'Electronics')), ('Energy', _lazy(u'Energy')), ('Engineering', _lazy(u'Engineering')), ('Entertainment', _lazy(u'Entertainment')), ('Environmental', _lazy(u'Environmental')), ('Finance', _lazy(u'Finance')), ('Food & Beverage', _lazy(u'Food & Beverage')), ('Government', _lazy(u'Government')), ('Healthcare', _lazy(u'Healthcare')), ('Hospitality', _lazy(u'Hospitality')), ('Insurance', _lazy(u'Insurance')), ('Machinery', _lazy(u'Machinery')), ('Manufacturing', _lazy(u'Manufacturing')), ('Media', _lazy(u'Media')), ('Not For Profit', _lazy(u'Not For Profit')), ('Other', _lazy(u'Other')), ('Recreation', _lazy(u'Recreation')), ('Retail', _lazy(u'Retail')), ('Shipping', _lazy(u'Shipping')), ('Technology', _lazy(u'Technology')), ('Telecommunications', _lazy(u'Telecommunications')), ('Transportation', _lazy(u'Transportation')), ('Utilities', _lazy(u'Utilities')), ) first_name = forms.CharField( max_length=40, required=True, error_messages={'required': _lazy(u'Please enter your first name.')}, widget=forms.TextInput( attrs={ 'size': 20, 'class': 'required', 'required': 'required', 'aria-required': 'true' })) last_name = forms.CharField( max_length=40, required=True, error_messages={'required': _lazy(u'Please enter your last name.')}, widget=forms.TextInput( attrs={ 'size': 20, 'class': 'required', 'required': 'required', 'aria-required': 'true' })) company = forms.CharField( max_length=40, required=True, error_messages={'required': _lazy(u'Please enter your company name.')}, widget=forms.TextInput( attrs={ 'size': 20, 'class': 'required', 'required': 'required', 'aria-required': 'true' })) email = forms.EmailField(max_length=80, required=True, error_messages={ 'required': _lazy(u'Please enter your email address.'), 'invalid': _lazy(u'Please enter a valid email address') }, widget=forms.TextInput( attrs={ 'size': 20, 'class': 'required', 'required': 'required', 'aria-required': 'true' })) phone = forms.CharField( max_length=40, required=True, error_messages={'required': _lazy(u'Please enter your phone number.')}, widget=forms.TextInput( attrs={ 'size': 20, 'class': 'required', 'required': 'required', 'aria-required': 'true' })) mobile = forms.CharField(max_length=40, required=False, widget=forms.TextInput(attrs={'size': 20})) street = forms.CharField(required=False, widget=forms.Textarea(attrs={ 'rows': '', 'cols': '' })) city = forms.CharField(required=False, max_length=40) state = USStateField(required=False, initial='', widget=USStateSelectBlank()) province = forms.CharField(required=False, max_length=40) country = forms.ChoiceField(required=True, ) zip = forms.CharField(required=False, max_length=40) campaign_type_description = forms.CharField( required=False, widget=forms.Textarea(attrs={ 'rows': '', 'cols': '' })) interested_countries = forms.CharField(required=False, widget=forms.Textarea(attrs={ 'rows': '', 'cols': '' })) interested_languages = forms.CharField(required=False, widget=forms.Textarea(attrs={ 'rows': '', 'cols': '' })) industry = forms.ChoiceField(choices=industries, required=False, widget=forms.Select(attrs={ 'title': _lazy('Industry'), 'size': 1 })) campaign_type = forms.ChoiceField( choices=(('', _lazy(u'Select Campaign Type')), ('Brand', _lazy(u'Brand')), ('Direct Response', _lazy(u'Direct Response')), ('Other', _lazy(u'Other'))), required=False, widget=forms.Select(attrs={'title': _lazy('Campaign Type')})) # honeypot office_fax = forms.CharField(widget=HoneyPotWidget, required=False) # uncomment below to debug salesforce # debug = forms.IntegerField(required=False) # debugEmail = forms.EmailField(required=False) def __init__(self, *args, **kwargs): kwargs.pop('lead_source', None) super(ContentServicesForm, self).__init__(*args, **kwargs) locale = kwargs.get('locale', 'en-US') country_list = product_details.get_regions(locale).items() country_list = sorted(country_list, key=lambda country: country[1]) country_list.insert(0, ('', '')) self.fields['country'].choices = country_list def clean(self): data = super(ContentServicesForm, self).clean() if data.get('country') == 'us' and not data.get('state'): raise ValidationError( self.fields['state'].error_messages['invalid']) return data
from lib.l10n_utils.fluent import ftl from bedrock.base import waffle from bedrock.base.urlresolvers import reverse # Cannot use short "from . import utils" because we need to mock # utils.get_newsletters in our tests from bedrock.base.views import get_geo_from_request from bedrock.newsletter import utils from .forms import (CountrySelectForm, EmailForm, ManageSubscriptionsForm, NewsletterFooterForm, NewsletterForm) log = commonware.log.getLogger('b.newsletter') LANG_FILES = ['mozorg/newsletters'] general_error = _lazy(u'We are sorry, but there was a problem ' u'with our system. Please try again later!') thank_you_new = _lazy( u'Your email preferences have been successfully updated.') thank_you = _lazy(u'Thanks for updating your email preferences.') bad_token = _lazy(u'The supplied link has expired or is not valid. You will ' u'receive a new one in the next newsletter, or below you ' u'can request an email with the link.') recovery_text = _lazy( u'Success! An email has been sent to you with your preference center ' u'link. Thanks!') # NOTE: Must format a link into this: (https://www.mozilla.org/newsletter/) unknown_address_text = _lazy( u'This email address is not in our system. Please double check your ' u'address or <a href="%s">subscribe to our newsletters.</a>')
from django.core.urlresolvers import reverse from django.forms import widgets from django.utils.safestring import mark_safe from localflavor.us.us_states import STATE_CHOICES import basket from basket.base import request from lib.l10n_utils.dotlang import _ from lib.l10n_utils.dotlang import _lazy from product_details import product_details from .email_contribute import INTEREST_CHOICES FORMATS = (('H', _lazy('HTML')), ('T', _lazy('Text'))) LANGS_TO_STRIP = ['en-US', 'es'] PARENTHETIC_RE = re.compile(r' \([^)]+\)$') LANG_FILES = [ 'firefox/partners/index', 'mozorg/contribute', 'mozorg/contribute/index', 'mozorg/newsletters' ] def strip_parenthetical(lang_name): """ Remove the parenthetical from the end of the language name string. """ return PARENTHETIC_RE.sub('', lang_name, 1)