Exemple #1
0
def contribute(request):
    def has_contribute_form():
        return request.method == "POST" and "contribute-form" in request.POST

    def has_newsletter_form():
        return request.method == "POST" and "newsletter-form" in request.POST

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

    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)
        success = handle_contribute_form(request, form)
    else:
        form = ContributeForm()

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

            try:
                basket.subscribe(data["email"], "about-mozilla", format=data["fmt"], country=data["country"])
                newsletter_success = True
            except basket.BasketException, e:
                msg = newsletter_form.error_class(
                    ["We apologize, but an error occurred in our system." "Please try again later."]
                )
                newsletter_form.errors["__all__"] = msg
Exemple #2
0
def contribute(request):
    def has_contribute_form():
        return (request.method == 'POST' and
                'contribute-form' in request.POST)

    def has_newsletter_form():
        return (request.method == 'POST' and
                'newsletter-form' in request.POST)


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

    success = False
    newsletter_success = False

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

        if form.is_valid():
            data = form.cleaned_data
            contribute_send(data)
            contribute_autorespond(request, data)

            if data['newsletter']:
                try:
                    basket.subscribe(data['email'], 'about-mozilla')
                except basket.BasketException, e: pass

            success = True
    else:
        form = ContributeForm()

    if has_newsletter_form():
        newsletter_form = NewsletterCountryForm(locale,
                                                request.POST,
                                                prefix='newsletter')
        if newsletter_form.is_valid():
            data = newsletter_form.cleaned_data

            try:
                basket.subscribe(data['email'],
                                 'about-mozilla',
                                 format=data['fmt'],
                                 country=data['country'])
                newsletter_success = True
            except basket.BasketException, e:
                msg = newsletter_form.error_class(
                    ['We apologize, but an error occurred in our system.'
                     'Please try again later.']
                )
                newsletter_form.errors['__all__'] = msg
Exemple #3
0
def contribute(request, template, return_to_form):
    def has_contribute_form():
        return (request.method == 'POST' and 'contribute-form' in request.POST)

    def has_newsletter_form():
        return (request.method == 'POST' and 'newsletter-form' in request.POST)

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

    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)
        success = handle_contribute_form(request, form)
        if success:
            # If form was submitted successfully, return a new, empty
            # one.
            form = ContributeForm()
    else:
        form = ContributeForm()

    if has_newsletter_form():
        newsletter_form = NewsletterCountryForm(locale,
                                                request.POST,
                                                prefix='newsletter')
        if newsletter_form.is_valid():
            data = newsletter_form.cleaned_data

            try:
                basket.subscribe(data['email'],
                                 'about-mozilla',
                                 format=data['fmt'],
                                 country=data['country'])
                newsletter_success = True
            except basket.BasketException, e:
                msg = newsletter_form.error_class([
                    'We apologize, but an error occurred in our system.'
                    'Please try again later.'
                ])
                newsletter_form.errors['__all__'] = msg
Exemple #4
0
            data = newsletter_form.cleaned_data

            try:
                basket.subscribe(data['email'],
                                 'about-mozilla',
                                 format=data['fmt'],
                                 country=data['country'])
                newsletter_success = True
            except basket.BasketException, e:
                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 = NewsletterCountryForm(locale, prefix='newsletter')

    return l10n_utils.render(
        request, template, {
            'form': form,
            'success': success,
            'newsletter_form': newsletter_form,
            'newsletter_success': newsletter_success,
            'return_to_form': return_to_form
        })


def contribute_send(data):
    ccs = {
        'QA': '*****@*****.**',
        'Thunderbird': '*****@*****.**',