Exemple #1
0
def hide_contrib_form(lang):
    """
    If the lang file for a locale exists and has the correct comment returns
    True, and False otherwise.
    :param lang: the language code
    :return: bool
    """
    return lang_file_has_tag("mozorg/contribute", lang, "hide_form")
Exemple #2
0
def hide_contrib_form(lang):
    """
    If the lang file for a locale exists and has the correct comment returns
    True, and False otherwise.
    :param lang: the language code
    :return: bool
    """
    return lang_file_has_tag("mozorg/contribute", lang, "hide_form")
Exemple #3
0
 def test_lang_file_has_tag(self):
     """
     `lang_file_has_tag` should return true if lang file has the
     comment, and false otherwise.
     """
     ok_(lang_file_has_tag('active_de_lang_file', 'de', 'active'))
     ok_(lang_file_has_tag('active_de_lang_file_bom', 'de', 'active'))
     ok_(not lang_file_has_tag('active_de_lang_file', 'es', 'active'))
     ok_(not lang_file_has_tag('inactive_de_lang_file', 'de', 'active'))
     ok_(not lang_file_has_tag('file_does_not_exist', 'de', 'active'))
     ok_(lang_file_has_tag('main', 'de', 'guten_tag'))
     ok_(not lang_file_has_tag('main', 'de', 'tag_after_non_tag_lines'))
     ok_(not lang_file_has_tag('main', 'de', 'no_such_tag'))
Exemple #4
0
 def test_lang_file_has_tag(self):
     """
     `lang_file_has_tag` should return true if lang file has the
     comment, and false otherwise.
     """
     ok_(lang_file_has_tag('active_de_lang_file', 'de', 'active'))
     ok_(lang_file_has_tag('active_de_lang_file_bom', 'de', 'active'))
     ok_(not lang_file_has_tag('active_de_lang_file', 'es', 'active'))
     ok_(not lang_file_has_tag('inactive_de_lang_file', 'de', 'active'))
     ok_(not lang_file_has_tag('file_does_not_exist', 'de', 'active'))
     ok_(lang_file_has_tag('main', 'de', 'guten_tag'))
     ok_(not lang_file_has_tag('main', 'de', 'tag_after_non_tag_lines'))
     ok_(not lang_file_has_tag('main', 'de', 'no_such_tag'))
 def test_lang_file_has_tag(self):
     """
     `lang_file_has_tag` should return true if lang file has the
     comment, and false otherwise.
     """
     ok_(lang_file_has_tag("active_de_lang_file", "de", "active"))
     ok_(lang_file_has_tag("active_de_lang_file_bom", "de", "active"))
     ok_(not lang_file_has_tag("active_de_lang_file", "es", "active"))
     ok_(not lang_file_has_tag("inactive_de_lang_file", "de", "active"))
     ok_(not lang_file_has_tag("file_does_not_exist", "de", "active"))
     ok_(lang_file_has_tag("main", "de", "guten_tag"))
     ok_(not lang_file_has_tag("main", "de", "tag_after_non_tag_lines"))
     ok_(not lang_file_has_tag("main", "de", "no_such_tag"))
Exemple #6
0
def hide_contrib_form(lang):
    """
    If the lang file for a locale exists and has the correct comment returns
    True, and False otherwise.
    :param lang: the language code
    :return: bool
    """
    # en-US has every tag, thus we special case the negative
    if lang == settings.LANGUAGE_CODE:
        return False

    return lang_file_has_tag("mozorg/contribute", lang, "hide_form")
Exemple #7
0
def contribute_signup(request):
    # for the new signup landing pages, a variant will be specified
    # using the URL parameter v
    variant = request.GET.get('v', '')

    if variant in ['1', '2']:
        return ContributeSignupNew.as_view(variant=variant)(request)
    else:
        use_new_form = lang_file_has_tag('mozorg/contribute/index',
                                         l10n_utils.get_locale(request),
                                         '2015_signup_form')
        view_class = ContributeSignup if use_new_form else ContributeSignupOldForm
        return view_class.as_view()(request)
Exemple #8
0
def contribute_signup(request):
    # for the new signup landing pages, a variant will be specified
    # using the URL parameter v
    variant = request.GET.get('v', '')

    if variant in ['1', '2']:
        return ContributeSignupNew.as_view(variant=variant)(request)
    else:
        use_new_form = lang_file_has_tag('mozorg/contribute/index',
                                         l10n_utils.get_locale(request),
                                         '2015_signup_form')
        view_class = ContributeSignup if use_new_form else ContributeSignupOldForm
        return view_class.as_view()(request)
Exemple #9
0
    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
Exemple #10
0
def updated(request):
    """View that users come to after submitting on the `existing`
    or `updated` pages.

    Optional query args:

    :param unsub: '1' means we are coming here after the user requested
    to unsubscribe all.  We want to ask them why. '2' means we are coming
    back here after they submitted the form saying why they unsubscribed
    all.

    """
    unsub = _post_or_get(request, 'unsub', '0')
    try:
        unsub = int(unsub)
    except ValueError:
        unsub = 0

    # Did they do an unsubscribe all?  then unsub=1 was passed
    unsubscribed_all = unsub == UNSUB_UNSUBSCRIBED_ALL
    # Did they submit their reason? then unsub=2 was passed
    reasons_submitted = unsub == UNSUB_REASONS_SUBMITTED

    # Token might also have been passed (on remove_all only)
    token = _post_or_get(request, 'token', None)
    # token must be a UUID
    if token is not None and not UUID_REGEX.match(token):
        token = None

    # Say thank you unless we're saying something more specific
    if not unsub:
        locale = l10n_utils.get_locale(request)

        if lang_file_has_tag('mozorg/newsletters', locale,
                             'newsletter_confirm_0320'):
            success_message = thank_you_new
        else:
            success_message = thank_you
        messages.add_message(request, messages.INFO, success_message)

    if request.method == 'POST' and reasons_submitted and token:
        # Tell basket about their reasons
        reasons = []

        # Paste together all the reasons that they submitted.  Actually,
        # paste together the English versions of the reasons they submitted,
        # so we can read them.  (Well, except for the free-form reason.)
        for i, reason in enumerate(REASONS):
            if _post_or_get(request, 'reason%d' % i):
                reasons.append(str(reason))
        if _post_or_get(request, 'reason-text-p'):
            reasons.append(_post_or_get(request, 'reason-text', ''))

        reason_text = "\n\n".join(reasons) + "\n\n"

        utils.custom_unsub_reason(token, reason_text)

    context = {
        'unsubscribed_all': unsubscribed_all,
        'reasons_submitted': reasons_submitted,
        'token': token,
        'reasons': enumerate(REASONS),
    }
    return l10n_utils.render(request, 'newsletter/updated.html', context)
Exemple #11
0
def contribute_signup(request):
    use_new_form = lang_file_has_tag('mozorg/contribute/index',
                                     l10n_utils.get_locale(request),
                                     '2015_signup_form')
    view_class = ContributeSignup if use_new_form else ContributeSignupOldForm
    return view_class.as_view()(request)
Exemple #12
0
def l10n_has_tag(ctx, tag, langfile=None):
    """Return boolean whether the given template's lang files have the given tag."""
    if langfile:
        return lang_file_has_tag(langfile, ctx['LANG'], tag)
    else:
        return template_has_tag(ctx['template'], ctx['LANG'], tag)
Exemple #13
0
def contribute_signup(request):
    use_new_form = lang_file_has_tag('mozorg/contribute/index',
                                     l10n_utils.get_locale(request),
                                     '2015_signup_form')
    view_class = ContributeSignup if use_new_form else ContributeSignupOldForm
    return view_class.as_view()(request)
Exemple #14
0
def l10n_has_tag(ctx, tag, langfile=None):
    """Return boolean whether the given template's lang files have the given tag."""
    if langfile:
        return lang_file_has_tag(langfile, ctx['LANG'], tag)
    else:
        return template_has_tag(ctx['template'], ctx['LANG'], tag)