<commit_before># This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import json
import re
from cgi import escape
from collections import defaultdict
from operator import itemgetter

from django.conf import settings
from django.contrib import messages
from django.forms.formsets import formset_factory
from django.http import HttpResponseRedirect
from django.shortcuts import redirect
from django.utils.safestring import mark_safe
from django.views.decorators.cache import never_cache

import basket
import basket.errors
import commonware.log
from jinja2 import Markup

import lib.l10n_utils as l10n_utils
import requests

from bedrock.base import waffle
from lib.l10n_utils.dotlang import _, _lazy
from bedrock.base.urlresolvers import reverse

from .forms import (EmailForm, ManageSubscriptionsForm, NewsletterForm, NewsletterFooterForm)
# Cannot use short "from . import utils" because we need to mock
# utils.get_newsletters in our tests
from bedrock.mozorg.util import HttpResponseJSON
from bedrock.newsletter import utils


log = commonware.log.getLogger('b.newsletter')

LANG_FILES = ['mozorg/newsletters']
general_error = _lazy(u'We are sorry, but there was a problem '
                      u'with our system. Please try again later!')
thank_you = _lazy(u'Thanks for updating your email preferences.')
bad_token = _lazy(u'The supplied link has expired or is not valid. You will '
                  u'receive a new one in the next newsletter, or below you '
                  u'can request an email with the link.')
recovery_text = _lazy(
    u'Success! An email has been sent to you with your preference center '
    u'link. Thanks!')

# NOTE: Must format a link into this: (https://www.mozilla.org/newsletter/)
unknown_address_text = _lazy(
    u'This email address is not in our system. Please double check your '
    u'address or <a href="%s">subscribe to our newsletters.</a>')

invalid_email_address = _lazy(u'This is not a valid email address. '
                              u'Please check the spelling.')

NEWSLETTER_STRINGS = {
    u'about-mozilla': {
        'description': _lazy(u'Bringing you the best new opportunities to help support the open Web.'),
        'title': _lazy(u'Mozilla Communities')},
    u'about-standards': {
        'title': _lazy(u'About Standards')},
    u'addon-dev': {
        'title': _lazy(u'Addon Development')},
    u'addons': {
        'title': _lazy(u'About Addons')},
    u'affiliates': {
        'description': _lazy(u'A monthly newsletter to keep you up to date with the '
                             u'Firefox Affiliates program.'),
        'title': _lazy(u'Firefox Affiliates')},
    u'ambassadors': {
        'description': _lazy(u'A monthly newsletter on how to get involved with Mozilla on your campus. '),
        'title': _lazy(u'Firefox Student Ambassadors')},
    u'app-dev': {
        'description': _lazy(u'A developer\u2019s guide to highlights of Web platform '
                             u'innovations, best practices, new documentation and more.'),
        'title': _lazy(u'Mozilla Developer Newsletter')},
    u'aurora': {
        'description': _lazy(u'Aurora'),
        'title': _lazy(u'Aurora')},
    u'beta': {
        'description': _lazy(u'Read about the latest features for Firefox desktop and mobile '
                             u'before the final release.'),
        'title': _lazy(u'Beta News')},
    u'download-firefox-android': {
        'title': _lazy(u'Download Firefox for Android')},
    u'download-firefox-androidsn': {
        'title': _lazy(u'Get Firefox for Android')},
    u'download-firefox-androidsnus': {
        'title': _lazy(u'Get Firefox for Android')},
    u'download-firefox-ios': {
        'title': _lazy(u'Download Firefox for iOS')},
    u'download-firefox-mobile': {
        'title': _lazy(u'Download Firefox for Mobile')},
    u'drumbeat': {
        'title': _lazy(u'Drumbeat Newsgroup')},
    u'firefox-accounts-journey': {
        'description': _lazy(u'Get the most out of your Firefox Account.'),
        'title': _lazy(u'Firefox Accounts Tips')},
    u'firefox-desktop': {
        'description': _lazy(u'Don\u2019t miss the latest announcements about our desktop browser.'),
        'title': _lazy(u'Firefox for desktop')},
    u'firefox-flicks': {
        'description': _lazy(u'Periodic email updates about our annual international film competition.'),
        'title': _lazy(u'Firefox Flicks')},
    u'firefox-ios': {
        'description': _lazy(u'Be the first to know when Firefox is available for iOS devices.'),
        'title': _lazy(u'Firefox iOS')},
    u'firefox-os': {
        'description': _lazy(u'Don\u2019t miss important news and updates about your Firefox OS device.'),
        'title': _lazy(u'Firefox OS smartphone owner?')},
    u'firefox-os-news': {
        'description': _lazy(u'A monthly newsletter and special announcements on how to get the most '
                             u'from your Firefox OS device, including the latest features and coolest '
                             u'Firefox Marketplace apps.'),
        'title': _lazy(u'Firefox OS + You')},
    u'firefox-tips': {
        'description': _lazy(u'Get a weekly tip on how to super-charge your Firefox experience.'),
        'title': _lazy(u'Firefox Weekly Tips')},
    u'get-android-embed': {
        'title': _lazy(u'Get Firefox for Android')},
    u'get-android-notembed': {
        'title': _lazy(u'Get Firefox for Android')},
    u'get-involved': {
        'title': _lazy(u'Get Involved')},
    u'join-mozilla': {
        'title': _lazy(u'Join Mozilla')},
    u'labs': {
        'title': _lazy(u'About Labs')},
    u'maker-party': {
        'description': u"Mozilla's largest celebration of making and learning on the web.",
        'title': _lazy(u'Maker Party')},
    u'marketplace': {
        'description': _lazy(u'Discover the latest, coolest HTML5 apps on Firefox OS.'),
        'title': _lazy(u'Firefox OS')},
    u'marketplace-android': {
        'title': _lazy(u'Android')},
    u'marketplace-desktop': {
        'title': _lazy(u'Desktop')},
    u'mobile': {
        'description': _lazy(u'Keep up with releases and news about Firefox for Android.'),
        'title': _lazy(u'Firefox for Android')},
    u'mozilla-and-you': {
        'description': _lazy(u'A monthly newsletter and special announcements giving you tips to '
                             u'improve your experience with Firefox on your desktop and Android device.'),
        'title': _lazy(u'Firefox + You')},
    u'mozilla-festival': {
        'description': u"Special announcements about Mozilla's annual, hands-on festival "
                       u"dedicated to forging the future of the open Web.",
        'title': _lazy(u'Mozilla Festival')},
    u'mozilla-foundation': {
        'description': _lazy(u'News and special updates about our work to promote openness, innovation '
                             u'and participation on the Internet, including ways for you to get involved.'),
        'title': _lazy(u'Mozilla Foundation')},<commit_msg>Fix bug 1402437: Change the Mozilla Foundation newsletter to just "Mozilla"<commit_after># This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import json
import re
from cgi import escape
from collections import defaultdict
from operator import itemgetter

from django.conf import settings
from django.contrib import messages
from django.forms.formsets import formset_factory
from django.http import HttpResponseRedirect
from django.shortcuts import redirect
from django.utils.safestring import mark_safe
from django.views.decorators.cache import never_cache

import basket
import basket.errors
import commonware.log
from jinja2 import Markup

import lib.l10n_utils as l10n_utils
import requests

from bedrock.base import waffle
from lib.l10n_utils.dotlang import _, _lazy
from bedrock.base.urlresolvers import reverse

from .forms import (EmailForm, ManageSubscriptionsForm, NewsletterForm, NewsletterFooterForm)
# Cannot use short "from . import utils" because we need to mock
# utils.get_newsletters in our tests
from bedrock.mozorg.util import HttpResponseJSON
from bedrock.newsletter import utils


log = commonware.log.getLogger('b.newsletter')

LANG_FILES = ['mozorg/newsletters']
general_error = _lazy(u'We are sorry, but there was a problem '
                      u'with our system. Please try again later!')
thank_you = _lazy(u'Thanks for updating your email preferences.')
bad_token = _lazy(u'The supplied link has expired or is not valid. You will '
                  u'receive a new one in the next newsletter, or below you '
                  u'can request an email with the link.')
recovery_text = _lazy(
    u'Success! An email has been sent to you with your preference center '
    u'link. Thanks!')

# NOTE: Must format a link into this: (https://www.mozilla.org/newsletter/)
unknown_address_text = _lazy(
    u'This email address is not in our system. Please double check your '
    u'address or <a href="%s">subscribe to our newsletters.</a>')

invalid_email_address = _lazy(u'This is not a valid email address. '
                              u'Please check the spelling.')

NEWSLETTER_STRINGS = {
    u'about-mozilla': {
        'description': _lazy(u'Bringing you the best new opportunities to help support the open Web.'),
        'title': _lazy(u'Mozilla Communities')},
    u'about-standards': {
        'title': _lazy(u'About Standards')},
    u'addon-dev': {
        'title': _lazy(u'Addon Development')},
    u'addons': {
        'title': _lazy(u'About Addons')},
    u'affiliates': {
        'description': _lazy(u'A monthly newsletter to keep you up to date with the '
                             u'Firefox Affiliates program.'),
        'title': _lazy(u'Firefox Affiliates')},
    u'ambassadors': {
        'description': _lazy(u'A monthly newsletter on how to get involved with Mozilla on your campus. '),
        'title': _lazy(u'Firefox Student Ambassadors')},
    u'app-dev': {
        'description': _lazy(u'A developer\u2019s guide to highlights of Web platform '
                             u'innovations, best practices, new documentation and more.'),
        'title': _lazy(u'Mozilla Developer Newsletter')},
    u'aurora': {
        'description': _lazy(u'Aurora'),
        'title': _lazy(u'Aurora')},
    u'beta': {
        'description': _lazy(u'Read about the latest features for Firefox desktop and mobile '
                             u'before the final release.'),
        'title': _lazy(u'Beta News')},
    u'download-firefox-android': {
        'title': _lazy(u'Download Firefox for Android')},
    u'download-firefox-androidsn': {
        'title': _lazy(u'Get Firefox for Android')},
    u'download-firefox-androidsnus': {
        'title': _lazy(u'Get Firefox for Android')},
    u'download-firefox-ios': {
        'title': _lazy(u'Download Firefox for iOS')},
    u'download-firefox-mobile': {
        'title': _lazy(u'Download Firefox for Mobile')},
    u'drumbeat': {
        'title': _lazy(u'Drumbeat Newsgroup')},
    u'firefox-accounts-journey': {
        'description': _lazy(u'Get the most out of your Firefox Account.'),
        'title': _lazy(u'Firefox Accounts Tips')},
    u'firefox-desktop': {
        'description': _lazy(u'Don\u2019t miss the latest announcements about our desktop browser.'),
        'title': _lazy(u'Firefox for desktop')},
    u'firefox-flicks': {
        'description': _lazy(u'Periodic email updates about our annual international film competition.'),
        'title': _lazy(u'Firefox Flicks')},
    u'firefox-ios': {
        'description': _lazy(u'Be the first to know when Firefox is available for iOS devices.'),
        'title': _lazy(u'Firefox iOS')},
    u'firefox-os': {
        'description': _lazy(u'Don\u2019t miss important news and updates about your Firefox OS device.'),
        'title': _lazy(u'Firefox OS smartphone owner?')},
    u'firefox-os-news': {
        'description': _lazy(u'A monthly newsletter and special announcements on how to get the most '
                             u'from your Firefox OS device, including the latest features and coolest '
                             u'Firefox Marketplace apps.'),
        'title': _lazy(u'Firefox OS + You')},
    u'firefox-tips': {
        'description': _lazy(u'Get a weekly tip on how to super-charge your Firefox experience.'),
        'title': _lazy(u'Firefox Weekly Tips')},
    u'get-android-embed': {
        'title': _lazy(u'Get Firefox for Android')},
    u'get-android-notembed': {
        'title': _lazy(u'Get Firefox for Android')},
    u'get-involved': {
        'title': _lazy(u'Get Involved')},
    u'join-mozilla': {
        'title': _lazy(u'Join Mozilla')},
    u'labs': {
        'title': _lazy(u'About Labs')},
    u'maker-party': {
        'description': u"Mozilla's largest celebration of making and learning on the web.",
        'title': _lazy(u'Maker Party')},
    u'marketplace': {
        'description': _lazy(u'Discover the latest, coolest HTML5 apps on Firefox OS.'),
        'title': _lazy(u'Firefox OS')},
    u'marketplace-android': {
        'title': _lazy(u'Android')},
    u'marketplace-desktop': {
        'title': _lazy(u'Desktop')},
    u'mobile': {
        'description': _lazy(u'Keep up with releases and news about Firefox for Android.'),
        'title': _lazy(u'Firefox for Android')},
    u'mozilla-and-you': {
        'description': _lazy(u'A monthly newsletter and special announcements giving you tips to '
                             u'improve your experience with Firefox on your desktop and Android device.'),
        'title': _lazy(u'Firefox')},
    u'mozilla-festival': {
        'description': u"Special announcements about Mozilla's annual, hands-on festival "
                       u"dedicated to forging the future of the open Web.",
        'title': _lazy(u'Mozilla Festival')},
    u'mozilla-foundation': {
        'description': _lazy(u'News and special updates about our work to promote openness, innovation '
                             u'and participation on the Internet, including ways for you to get involved.'),
        'title': _lazy(u'Mozilla')},
{'fraction_non_alphanumeric': 0.11645499340689847, 'fraction_numerical': 0.003817058782705254, 'mean_word_length': 3.056869369369369, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6689373', 'n_tokens_mistral': 4456, 'n_tokens_neox': 4340, 'n_words': 1359}