Example #1
0
    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
Example #2
0
    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
Example #3
0
    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__()
        print lang_files_list
        call_lang_files = lang_files_list + settings.DOTLANG_FILES
        trans_patch.assert_called_with(trans_str, call_lang_files)
Example #4
0
    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__()
        print lang_files_list
        call_lang_files = lang_files_list + settings.DOTLANG_FILES
        trans_patch.assert_called_with(trans_str, call_lang_files)
Example #5
0
    def process_request(self, 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():
                data = form.cleaned_data
                try:
                    basket.subscribe(data['email'], data['newsletter'],
                                     format=data['fmt'])
                    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
Example #6
0
    def process_request(self, 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():
                data = form.cleaned_data
                try:
                    basket.subscribe(data['email'],
                                     data['newsletter'],
                                     format=data['fmt'])
                    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
Example #7
0
from django.conf import settings
from django.forms import widgets
from django.utils.safestring import mark_safe

import basket
from basket.base import request

from captcha.fields import ReCaptchaField
from l10n_utils.dotlang import _
from 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 = settings.NEWSLETTER_LANGUAGES
LANGS_TO_STRIP = ['en-US', 'es']
PARENTHETIC_RE = re.compile(r' \([^)]+\)$')
LANG_FILES = 'mozorg/contribute'


def strip_parenthetical(lang_name):
    """
    Remove the parenthetical from the end of the language name string.
    """
    return PARENTHETIC_RE.sub('', lang_name, 1)


def get_lang_choices():
    """