Beispiel #1
0
class PressInquiryForm(forms.Form):
    jobtitle = forms.CharField(required=True, widget=forms.TextInput(attrs={"class": "required", "required": "required", "aria-required": "true"}))
    name = forms.CharField(required=True, widget=forms.TextInput(attrs={"class": "required", "required": "required", "aria-required": "true"}))
    user_email = forms.EmailField(
        max_length=254,  # max length allowed for emails
        required=True,
        widget=EmailInput(
            attrs={
                "required": "required",
                "class": "required",
                "aria-required": "true",
            }
        ),
    )
    media_org = forms.CharField(required=True, widget=forms.TextInput(attrs={"class": "required", "required": "required", "aria-required": "true"}))
    inquiry = forms.CharField(
        required=True, widget=forms.Textarea(attrs={"class": "required", "required": "required", "aria-required": "true", "rows": "", "cols": ""})
    )
    deadline = forms.CharField(required=True, widget=DateInput(attrs={"class": "required", "required": "required", "aria-required": "true"}))

    # honeypot
    office_fax = forms.CharField(widget=HoneyPotWidget, required=False)

    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"))
Beispiel #2
0
class PressInquiryForm(forms.Form):
    jobtitle = forms.CharField(
        required=True,
        widget=forms.TextInput(attrs={
            'class': 'required',
            'required': 'required',
            'aria-required': 'true'
        }))
    name = forms.CharField(
        required=True,
        widget=forms.TextInput(attrs={
            'class': 'required',
            'required': 'required',
            'aria-required': 'true'
        }))
    user_email = forms.EmailField(
        max_length=254,  # max length allowed for emails
        required=True,
        widget=EmailInput(attrs={
            'required': 'required',
            'class': 'required',
            'aria-required': 'true',
        }),
    )
    media_org = forms.CharField(
        required=True,
        widget=forms.TextInput(attrs={
            'class': 'required',
            'required': 'required',
            'aria-required': 'true'
        }))
    inquiry = forms.CharField(required=True,
                              widget=forms.Textarea(
                                  attrs={
                                      'class': 'required',
                                      'required': 'required',
                                      'aria-required': 'true',
                                      'rows': '',
                                      'cols': ''
                                  }))
    deadline = forms.CharField(
        required=True,
        widget=DateInput(attrs={
            'class': 'required',
            'required': 'required',
            'aria-required': 'true'
        }))

    # honeypot
    office_fax = forms.CharField(widget=HoneyPotWidget, required=False)

    def clean_office_fax(self):
        cleaned_data = super(PressInquiryForm, self).clean()
        honeypot = cleaned_data.pop('office_fax', None)

        if honeypot:
            raise forms.ValidationError(
                _('Your submission could not be processed'))
Beispiel #3
0
class NewsletterFooterForm(forms.Form):
    """
    Form used to subscribe to a single newsletter, typically in the
    footer of a page (see newsletters/middleware.py) but sometimes
    on a dedicated page.
    """
    newsletter = forms.CharField(widget=forms.HiddenInput)
    email = forms.EmailField(widget=EmailInput(attrs={'required': 'required'}))
    fmt = forms.ChoiceField(widget=forms.RadioSelect(renderer=SideRadios),
                            choices=FORMATS,
                            initial='H')
    privacy = forms.BooleanField(widget=PrivacyWidget)
    source_url = forms.URLField(verify_exists=False, required=False)

    def __init__(self, locale, *args, **kwargs):
        regions = product_details.get_regions(locale)
        regions = sorted(regions.iteritems(), key=lambda x: x[1])

        lang = country = locale.lower()
        if '-' in lang:
            lang, country = lang.split('-', 1)
        lang_choices = get_lang_choices()
        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, (lang, lang))

        super(NewsletterFooterForm, self).__init__(*args, **kwargs)
        self.fields['country'] = forms.ChoiceField(choices=regions,
                                                   initial=country,
                                                   required=False)
        # TypedChoiceField knows that '' is an empty choice, and with
        # required=True, will not accept '' as valid input.
        select_widget = widgets.Select(attrs={'required': 'required'})
        self.fields['lang'] = forms.TypedChoiceField(widget=select_widget,
                                                     choices=lang_choices,
                                                     initial=lang,
                                                     required=True,
                                                     empty_value='')

    def clean_newsletter(self):
        # We didn't want to have to look up the list of valid newsletters
        # until we actually had a form submitted
        newsletter = self.cleaned_data.get('newsletter', None)
        if newsletter:
            newsletters = newsletter.replace(' ', '').split(',')
            valid_newsletters = utils.get_newsletters().keys()
            for nl in newsletters:
                if nl not in valid_newsletters:
                    raise ValidationError("%s is not a valid newsletter" % nl)
            return ','.join(newsletters)
Beispiel #4
0
class NewsletterFooterForm(forms.Form):
    """
    Form used to subscribe to a single newsletter, typically in the
    footer of a page (see newsletters/middleware.py) but sometimes
    on a dedicated page.
    """
    email = forms.EmailField(widget=EmailInput(attrs={'required': 'required'}))
    fmt = forms.ChoiceField(widget=forms.RadioSelect(renderer=SideRadios),
                            choices=FORMATS,
                            initial='H')
    privacy = forms.BooleanField(widget=PrivacyWidget)
    source_url = forms.URLField(required=False)

    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)
Beispiel #5
0
class EmailForm(forms.Form):
    """
    Form to enter email, e.g. to be sent a recovery message
    """
    email = forms.EmailField(widget=EmailInput(attrs={'required': 'required'}))
Beispiel #6
0
class NewsletterFooterForm(forms.Form):
    """
    Form used to subscribe to a single newsletter, typically in the
    footer of a page (see newsletters/middleware.py) but sometimes
    on a dedicated page.
    """
    email = forms.EmailField(widget=EmailInput(attrs={'required': 'required'}))
    # first/last_name not yet included in email_newsletter_form helper
    # currently used on /contribute/friends/ (custom markup)
    first_name = forms.CharField(widget=forms.TextInput, required=False)
    last_name = forms.CharField(widget=forms.TextInput, required=False)
    fmt = forms.ChoiceField(widget=SimpleRadioSelect,
                            choices=FORMATS,
                            initial='H')
    privacy = forms.BooleanField(widget=PrivacyWidget)
    source_url = forms.CharField(required=False)
    newsletters = forms.CharField(widget=forms.HiddenInput,
                                  required=True,
                                  max_length=100)

    # has to take a newsletters argument so it can figure
    # out which languages to list in the form.
    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 = ''
            regions.insert(0, ('', ftl_lazy('newsletter-form-select-country-or-region',
                                            fallback='newsletter-form-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, ('', ftl_lazy('newsletter-form-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 clean_newsletters(self):
        return validate_newsletters(self.cleaned_data['newsletters'])

    def clean_source_url(self):
        su = self.cleaned_data['source_url'].strip()
        if su:
            # limit to 255 characters by truncation
            return su[:255]

        return su
Beispiel #7
0
class NewsletterFooterForm(forms.Form):
    """
    Form used to subscribe to a single newsletter, typically in the
    footer of a page (see newsletters/middleware.py) but sometimes
    on a dedicated page.
    """

    choice_labels = {
        "mozilla-foundation":
        ftl("multi-newsletter-form-checkboxes-label-mozilla"),
        "mozilla-and-you":
        ftl("multi-newsletter-form-checkboxes-label-firefox"),
    }

    email = forms.EmailField(widget=EmailInput(attrs={"required": "required"}))
    # first/last_name not yet included in email_newsletter_form helper
    # currently used on /contribute/friends/ (custom markup)
    first_name = forms.CharField(widget=forms.TextInput, required=False)
    last_name = forms.CharField(widget=forms.TextInput, required=False)
    fmt = forms.ChoiceField(widget=SimpleRadioSelect,
                            choices=FORMATS,
                            initial="H")
    privacy = forms.BooleanField(widget=PrivacyWidget)
    source_url = forms.CharField(required=False)
    newsletters = forms.MultipleChoiceField(
        widget=forms.CheckboxSelectMultiple())

    # has to take a newsletters argument so it can figure
    # out which languages to list in the form.
    def __init__(self, newsletters, locale, data=None, *args, **kwargs):
        regions = product_details.get_regions(locale)
        regions = sorted(iter(regions.items()), key=itemgetter(1))

        try:
            if isinstance(newsletters, str):
                newsletters = newsletters.split(",")
            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, ("",
                    ftl_lazy("newsletter-form-select-country-or-region",
                             fallback="newsletter-form-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, ("", ftl_lazy("newsletter-form-available-languages")))

        super().__init__(data, *args, **kwargs)

        required_args = {
            "required": "required",
            "aria-required": "true",
        }
        country_widget = widgets.Select(attrs=required_args)
        country_label = ftl_lazy("newsletter-form-select-country-or-region",
                                 fallback="newsletter-form-select-country")
        self.fields["country"] = forms.ChoiceField(widget=country_widget,
                                                   choices=regions,
                                                   initial=country,
                                                   required=False,
                                                   label=country_label)
        lang_widget = widgets.Select(attrs=required_args)
        lang_label = ftl_lazy("newsletter-form-select-language",
                              fallback="newsletter-form-available-languages")
        self.fields["lang"] = forms.TypedChoiceField(widget=lang_widget,
                                                     choices=lang_choices,
                                                     initial=lang,
                                                     required=False,
                                                     label=lang_label)
        self.fields["newsletters"].choices = [(n, self.choice_labels.get(n, n))
                                              for n in newsletters]
        self.fields["newsletters"].initial = newsletters

    def clean_newsletters(self):
        return validate_newsletters(self.cleaned_data["newsletters"])

    def clean_source_url(self):
        su = self.cleaned_data["source_url"].strip()
        if su:
            # limit to 255 characters by truncation
            return su[:255]

        return su
Beispiel #8
0
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'))
Beispiel #9
0
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"))