コード例 #1
0
ファイル: middleware.py プロジェクト: DonnieThomas/bedrock
    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
コード例 #2
0
ファイル: middleware.py プロジェクト: tikimaster/bedrock
    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
コード例 #3
0
ファイル: views.py プロジェクト: alicelieutier/bedrock
def contribute(request, template, return_to_form):
    has_contribute_form = (request.method == 'POST' and
                           'contribute-form' in request.POST)

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

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

    contribute_success = False
    newsletter_success = False

    # This is ugly, but we need to handle two forms. I would love if
    # these forms could post to separate pages and get redirected
    # back, but we're forced to keep the error/success workflow on the
    # same page. Please change this.
    if has_contribute_form:
        form = ContributeForm(request.POST)
        contribute_success = email_contribute.handle_form(request, form)
        if contribute_success:
            # If form was submitted successfully, return a new, empty
            # one.
            form = ContributeForm()
    else:
        form = ContributeForm()

    if has_newsletter_form:
        newsletter_form = NewsletterForm(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:
                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 = NewsletterForm(locale, prefix='newsletter')

    return l10n_utils.render(request,
                             template,
                             {'form': form,
                              'contribute_success': contribute_success,
                              'newsletter_form': newsletter_form,
                              'newsletter_success': newsletter_success,
                              'return_to_form': return_to_form,
                              'hide_form': hide_contrib_form(request.locale),
                              'has_moz15': locale in settings.LOCALES_WITH_MOZ15})
コード例 #4
0
ファイル: views.py プロジェクト: ppapadeas/bedrock
def partners(request):
    success = False
    form = NewsletterForm(request.POST or None)

    if request.method == 'POST':
        if form.is_valid():
            data = form.cleaned_data
            basket.subscribe(data['email'], 'app-dev', format=data['fmt'])
            success = True

    return l10n_utils.render(request, "marketplace/partners.html", {
        'form': form,
        'success': success
    })
コード例 #5
0
ファイル: views.py プロジェクト: shawnl/bedrock
def marketplace(request):
    success = False
    form = NewsletterForm(request.POST or None)

    if request.method == 'POST':
        if form.is_valid():
            data = form.cleaned_data
            basket.subscribe(data['email'], 'app-dev', format=data['fmt'])
            success = True
            
    return l10n_utils.render(request,
                             "marketplace/marketplace.html",
                             {'form': form,
                              'success': success})
コード例 #6
0
ファイル: util.py プロジェクト: andrewhayward/bedrock
def handle_newsletter(request):
    success = False
    form = NewsletterForm(request.POST or None)

    is_footer_form = (request.method == 'POST' and
                      'newsletter-footer' in request.POST)
    if is_footer_form:
        if form.is_valid():
            newsletter = request.POST['newsletter']
            data = form.cleaned_data

            try:
                basket.subscribe(data['email'], newsletter, format=data['fmt'])
                success = True
            except basket.BasketException, e:
                msg = ("We are sorry, but there was a problem with our system. "
                       "Please try again later!")
                form.errors['__all__'] = form.error_class([msg])
コード例 #7
0
def handle_newsletter(request):
    success = False
    form = NewsletterForm(request.POST or None)

    is_footer_form = (request.method == 'POST'
                      and 'newsletter-footer' in request.POST)
    if is_footer_form:
        if form.is_valid():
            newsletter = request.POST['newsletter']
            data = form.cleaned_data

            try:
                basket.subscribe(data['email'], newsletter, format=data['fmt'])
                success = True
            except basket.BasketException, e:
                msg = (
                    "We are sorry, but there was a problem with our system. "
                    "Please try again later!")
                form.errors['__all__'] = form.error_class([msg])
コード例 #8
0
ファイル: views.py プロジェクト: tikimaster/bedrock
def contribute(request, template, return_to_form):
    has_contribute_form = (request.method == 'POST'
                           and 'contribute-form' in request.POST)

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

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

    contribute_success = False
    newsletter_success = False

    # This is ugly, but we need to handle two forms. I would love if
    # these forms could post to separate pages and get redirected
    # back, but we're forced to keep the error/success workflow on the
    # same page. Please change this.
    if has_contribute_form:
        form = ContributeForm(request.POST)
        contribute_success = email_contribute.handle_form(request, form)
        if contribute_success:
            # If form was submitted successfully, return a new, empty
            # one.
            form = ContributeForm()
    else:
        form = ContributeForm()

    if has_newsletter_form:
        newsletter_form = NewsletterForm(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:
                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 = NewsletterForm(locale, prefix='newsletter')

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