def get_template_names(self): locale = l10n_utils.get_locale(self.request) trailhead_locales = ['en-US', 'en-CA', 'en-GB', 'de', 'fr'] version = self.kwargs.get('version') or '' oldversion = self.request.GET.get('oldversion', '') # old versions of Firefox sent a prefixed version if oldversion.startswith('rv:'): oldversion = oldversion[3:] channel = detect_channel(version) if channel == 'nightly': template = 'firefox/nightly_whatsnew.html' elif channel == 'alpha': if version.startswith('68.') and switch('dev_whatsnew_68'): if locale in trailhead_locales and switch( 'dev_whatsnew_68_trailhead'): template = 'firefox/developer/whatsnew-fx68-trailhead.html' else: template = 'firefox/developer/whatsnew-fx68.html' elif show_57_dev_whatsnew(version): template = 'firefox/developer/whatsnew.html' else: template = 'firefox/dev-whatsnew.html' elif channel == 'beta': if version.startswith('68.'): if locale in trailhead_locales and switch( 'beta_whatsnew_68_trailhead'): template = 'firefox/whatsnew/beta/whatsnew-fx68-trailhead.html' else: template = 'firefox/whatsnew/beta/whatsnew-fx68.html' else: template = 'firefox/whatsnew/index.html' elif locale == 'id': template = 'firefox/whatsnew/index-lite.id.html' elif version.startswith('68.'): if locale in trailhead_locales: template = 'firefox/whatsnew/whatsnew-fx68-trailhead.html' else: template = 'firefox/whatsnew/whatsnew-fx68.html' elif version.startswith('67.0.') and locale in trailhead_locales: template = 'firefox/whatsnew/whatsnew-fx67.0.5.html' elif version.startswith('67.'): template = 'firefox/whatsnew/whatsnew-fx67.html' elif version.startswith('66.'): template = 'firefox/whatsnew/whatsnew-fx66.html' elif version.startswith('65.'): template = 'firefox/whatsnew/whatsnew-fx65.html' elif version.startswith('64.'): template = 'firefox/whatsnew/fx64/whatsnew-fx64.html' elif version.startswith('63.'): template = 'firefox/whatsnew/whatsnew-fx63.html' else: template = 'firefox/whatsnew/index.html' # return a list to conform with original intention return [template]
def home_view(request): locale = l10n_utils.get_locale(request) donate_params = settings.DONATE_PARAMS.get(locale, settings.DONATE_PARAMS["en-US"]) # make sure we POST to a know locale, to avoid 404 errors. donate_locale = locale if locale in settings.DONATE_PARAMS else "en-US" # presets are stored as a string but, for the home banner # we need it as a list. donate_params["preset_list"] = donate_params["presets"].split(",") ctx = { "donate_locale": donate_locale, "donate_params": donate_params, "pocket_articles": PocketArticle.objects.all()[:4], "ftl_files": ["mozorg/home", "mozorg/home-mr2-promo"], "add_active_locales": ["de", "fr"], } if locale.startswith("en-"): if switch("contentful-homepage-en"): try: template_name = "mozorg/home/home-contentful.html" # TODO: use a better system to get the pages than the ID ctx.update( ContentfulEntry.objects.get_page_by_id( content_id=settings.CONTENTFUL_HOMEPAGE_LOOKUP["en-US"] )) except Exception as ex: capture_exception(ex) # if anything goes wrong, use the rest-of-world home page template_name = "mozorg/home/home.html" else: template_name = "mozorg/home/home.html" elif locale == "de": if switch("contentful-homepage-de"): try: template_name = "mozorg/home/home-contentful.html" ctx.update( ContentfulEntry.objects.get_page_by_id( content_id=settings.CONTENTFUL_HOMEPAGE_LOOKUP["de"])) except Exception as ex: capture_exception(ex) # if anything goes wrong, use the old page template_name = "mozorg/home/home-de.html" ctx["page_content_cards"] = get_page_content_cards( "home-de", "de") else: template_name = "mozorg/home/home-de.html" ctx["page_content_cards"] = get_page_content_cards("home-de", "de") elif locale == "fr": template_name = "mozorg/home/home-fr.html" ctx["page_content_cards"] = get_page_content_cards("home-fr", "fr") else: template_name = "mozorg/home/home.html" return l10n_utils.render(request, template_name, ctx)
def new(request): # Remove legacy query parameters (Bug 1236791) if request.GET.get('product', None) or request.GET.get('os', None): return HttpResponsePermanentRedirect(reverse('firefox.new')) scene = request.GET.get('scene', None) experience = request.GET.get('xv', None) variant = request.GET.get('v', None) locale = l10n_utils.get_locale(request) # ensure variant matches pre-defined value if variant not in ['a', 'b', '1', '2', '3']: variant = None if scene == '2': # `wait-face`, `reggiewatts` variations are currently localized for both en-US and de locales. if lang_file_is_active('firefox/new/wait-face', locale) and experience == 'waitface': template = 'firefox/new/wait-face/scene2.html' elif lang_file_is_active('firefox/new/reggiewatts', locale) and experience == 'reggiewatts': template = 'firefox/new/reggie-watts/scene2.html' else: template = 'firefox/new/scene2.html' # if no/incorrect scene specified, show scene 1 else: if lang_file_is_active('firefox/new/wait-face', locale) and experience == 'waitface': if switch('experiment-firefox-new-waitface'): if variant == 'b': template = 'firefox/new/wait-face/scene1-video.html' else: template = 'firefox/new/wait-face/scene1.html' elif switch('experiment-firefox-new-waitface-switch'): if variant == '2': template = 'firefox/new/wait-face/scene1-newcopy.html' elif variant == '3': template = 'firefox/new/wait-face/scene1-switch.html' else: template = 'firefox/new/wait-face/scene1.html' else: template = 'firefox/new/wait-face/scene1.html' elif lang_file_is_active('firefox/new/reggiewatts', locale) and experience == 'reggiewatts': template = 'firefox/new/reggie-watts/scene1.html' else: template = 'firefox/new/scene1.html' return l10n_utils.render(request, template, {'v': variant})
def get_template_names(self): version = self.kwargs.get('version') or '' experience = self.request.GET.get('xv', None) locale = l10n_utils.get_locale(self.request) # for copy test # https://bugzilla.mozilla.org/show_bug.cgi?id=1451051 variation = self.request.GET.get('v', None) if detect_channel(version) == 'alpha': if show_57_dev_firstrun(version): template = 'firefox/developer/firstrun.html' else: template = 'firefox/dev-firstrun.html' elif show_57_firstrun(version): if (switch('firefox-facebook-container-funnelcake') and locale == 'en-US' and experience == 'facebook-container'): template = 'firefox/firstrun/facebook-container.html' else: if locale == 'en-US' and variation in ['a', 'b', 'c', 'd']: template = 'firefox/firstrun/firstrun-quantum-{}.html'.format( variation) else: template = 'firefox/firstrun/firstrun-quantum.html' else: template = 'firefox/firstrun/index.html' # return a list to conform with original intention return [template]
def get_template_names(self): if switch('firefox-57-release'): template = 'firefox/features/quantum/password-manager.html' else: template = 'firefox/features/password-manager.html' return [template]
def get_template_names(self): if switch('firefox-57-release'): template = 'firefox/features/quantum/independent.html' else: template = 'firefox/features/independent.html' return [template]
def get_template_names(self): if switch('firefox-57-release'): template = 'firefox/features/quantum/private-browsing.html' else: template = 'firefox/features/private-browsing.html' return [template]
def features(request): if switch('firefox-57-release'): template = 'firefox/features/quantum/index.html' else: template = 'firefox/features/index.html' return l10n_utils.render(request, template)
def firefox_home(request): locale = l10n_utils.get_locale(request) variant = request.GET.get('v', None) newsletter_locales = ['en-US', 'en-GB', 'en-CA', 'en-ZA', 'fr', 'de'] show_newsletter = (switch('firefox_pre_download_newsletter') and locale in newsletter_locales) # ensure variant matches pre-defined value if variant not in [ 'a', 'b', 'c', 'd', 'e', ]: # place expected ?v= values in this list variant = None if locale == 'en-US' and variant is not None and variant != 'a': template = 'firefox/home/index-b.html' else: template = 'firefox/home/index.html' return l10n_utils.render(request, template, { 'show_newsletter': show_newsletter, 'variation': variant })
def get_template_names(self): version = self.kwargs.get('version') or '' experience = self.request.GET.get('xv', None) locale = l10n_utils.get_locale(self.request) # for copy test # https://bugzilla.mozilla.org/show_bug.cgi?id=1451051 variation = self.request.GET.get('v', None) if detect_channel(version) == 'alpha': if show_57_dev_firstrun(version): template = 'firefox/developer/firstrun.html' else: template = 'firefox/dev-firstrun.html' elif show_57_firstrun(version): if (switch('firefox-facebook-container-funnelcake') and locale == 'en-US' and experience == 'facebook-container'): template = 'firefox/firstrun/facebook-container.html' else: if locale == 'en-US' and variation in ['a', 'b', 'c', 'd']: template = 'firefox/firstrun/firstrun-quantum-{}.html'.format(variation) else: template = 'firefox/firstrun/firstrun-quantum.html' else: template = 'firefox/firstrun/index.html' # return a list to conform with original intention return [template]
def get_template_names(self): version = self.kwargs.get('version') or '' experience = self.request.GET.get('xv', None) locale = l10n_utils.get_locale(self.request) if detect_channel(version) == 'alpha': if show_57_dev_firstrun(version): template = 'firefox/developer/firstrun.html' else: template = 'firefox/dev-firstrun.html' elif show_57_firstrun(version): if (switch('firefox-facebook-container-funnelcake') and locale == 'en-US' and experience == 'facebook-container'): template = 'firefox/firstrun/facebook-container.html' else: template = 'firefox/firstrun/firstrun-quantum.html' elif show_40_firstrun(version): template = 'firefox/firstrun/index.html' elif show_38_0_5_firstrun(version): template = 'firefox/australis/fx38_0_5/firstrun.html' else: template = 'firefox/australis/firstrun.html' # return a list to conform with original intention return [template]
def vpn_variable_price_countries(): if switch('vpn-variable-pricing-wave-1'): countries = settings.VPN_FIXED_PRICE_COUNTRY_CODES + settings.VPN_VARIABLE_PRICE_COUNTRY_CODES return '|%s|' % '|'.join(cc.lower() for cc in countries) else: countries = settings.VPN_VARIABLE_PRICE_COUNTRY_CODES return '|%s|' % '|'.join(cc.lower() for cc in countries)
def get_template_names(self): locale = l10n_utils.get_locale(self.request) variant = self.request.GET.get('v', None) # ensure variant matches pre-defined value if variant not in self.variations: variant = None if locale == 'ru' and switch('firefox-yandex'): template = 'firefox/new/trailhead/download-yandex.html' elif ftl_file_is_active('firefox/new/desktop') and switch('new-redesign'): template = 'firefox/new/desktop/download.html' else: template = 'firefox/new/trailhead/download.html' return [template]
def sync_page(request): if switch('firefox-57-release'): template = 'firefox/features/quantum/sync.html' else: template = 'firefox/features/sync.html' return l10n_utils.render(request, template)
def get_template_names(self): if switch('firefox-57-release'): template = 'firefox/features/quantum/bookmarks.html' else: template = 'firefox/features/bookmarks.html' return [template]
def get_template_names(self): if ftl_file_is_active('firefox/new/desktop') and switch('new-redesign'): template = 'firefox/new/desktop/thanks.html' else: template = 'firefox/new/trailhead/thanks.html' return [template]
def firefox_home(request): locale = l10n_utils.get_locale(request) newsletter_locales = ['en-US', 'en-GB', 'en-CA', 'en-ZA', 'fr', 'de'] show_newsletter = switch( 'firefox_pre_download_newsletter') and locale in newsletter_locales return l10n_utils.render(request, 'firefox/home/index.html', {'show_newsletter': show_newsletter})
def get_template_names(self): locale = l10n_utils.get_locale(self.request) if switch('firefox-57-release') and lang_file_is_active( 'firefox/hub/home-quantum', locale): template_name = 'firefox/hub/home-quantum.html' else: template_name = 'firefox/hub/home.html' return [template_name]
def home(request): locale = l10n_utils.get_locale(request) if locale == 'en-US' and switch('experiment-home-q32017'): template = 'mozorg/home/home-b.html' else: template = 'mozorg/home/home.html' return l10n_utils.render(request, template)
def show_firefox_lite_whatsnew(version): try: version = Version(version) except ValueError: return False if not switch('firefox-lite-whatsnew'): return False return version >= Version('79.0')
def FirefoxProductDeveloperView(request): locale = l10n_utils.get_locale(request) if lang_file_is_active('firefox/products/developer-quantum', locale) and switch('fx-product-page-dev-quantum'): template = 'firefox/products/developer-quantum.html' else: template = 'firefox/products/developer.html' return l10n_utils.render(request, template)
def get_template_names(self): variation = self.request.GET.get('v', None) locale = l10n_utils.get_locale(self.request) version = self.kwargs.get('version') or '' oldversion = self.request.GET.get('oldversion', '') # old versions of Firefox sent a prefixed version if oldversion.startswith('rv:'): oldversion = oldversion[3:] channel = detect_channel(version) if channel == 'nightly': template = 'firefox/nightly_whatsnew.html' elif channel == 'developer': if show_57_dev_whatsnew(version): template = 'firefox/developer/whatsnew.html' else: template = 'firefox/whatsnew/index.html' elif locale == 'id' and show_firefox_lite_whatsnew(version): template = 'firefox/whatsnew/firefox-lite.id.html' elif version.startswith('79.') and ftl_file_is_active( 'firefox/whatsnew/whatsnew-fx79'): template = 'firefox/whatsnew/whatsnew-fx79.html' elif version.startswith('78.'): variations = ['2', '3', '4', '5'] locales = ['en-US', 'en-CA', 'en-GB', 'de', 'fr'] if variation in variations and locale in locales: locale = locale.split('-')[0] template = 'firefox/whatsnew/whatsnew-fx78-{0}-{1}.html'.format( variation, locale) else: template = 'firefox/whatsnew/whatsnew-fx78.html' elif version.startswith('77.') and lang_file_is_active( 'firefox/whatsnew_77', locale): # YouTube is blocked in China so zh-CN gets an alternative, self-hosted video. # If we run into bandwidth trouble we can turn the video off and zh-CN falls back to the 76 page. if locale == 'zh-CN' and not switch( 'firefox-whatsnew77-video-zhCN'): template = 'firefox/whatsnew/whatsnew-fx76.html' else: template = 'firefox/whatsnew/whatsnew-fx77.html' elif version.startswith('76.') and lang_file_is_active( 'firefox/whatsnew_76', locale): template = 'firefox/whatsnew/whatsnew-fx76.html' else: if show_default_account_whatsnew(version) and ftl_file_is_active( 'firefox/whatsnew/whatsnew-account'): template = 'firefox/whatsnew/index-account.html' else: template = 'firefox/whatsnew/index.html' # return a list to conform with original intention return [template]
def get_template_names(self): locale = l10n_utils.get_locale(self.request) version = self.kwargs.get('version') or '' oldversion = self.request.GET.get('oldversion', '') # old versions of Firefox sent a prefixed version if oldversion.startswith('rv:'): oldversion = oldversion[3:] channel = detect_channel(version) if channel == 'alpha': if show_57_dev_whatsnew(version): template = 'firefox/developer/whatsnew.html' else: template = 'firefox/dev-whatsnew.html' elif channel == 'nightly': template = 'firefox/nightly_whatsnew.html' elif locale == 'id': if switch('firefox_lite_whatsnew'): template = 'firefox/whatsnew/index-lite.id.html' else: template = 'firefox/whatsnew/index.id.html' elif locale == 'zh-TW' and not version.startswith('64.'): template = 'firefox/whatsnew/index.zh-TW.html' elif version.startswith('66.'): template = 'firefox/whatsnew/whatsnew-fx66.html' elif version.startswith('65.'): template = 'firefox/whatsnew/whatsnew-fx65.html' elif version.startswith('64.'): template = 'firefox/whatsnew/fx64/whatsnew-fx64.html' elif version.startswith('63.'): template = 'firefox/whatsnew/whatsnew-fx63.html' elif show_62_whatsnew(version, oldversion): template = 'firefox/whatsnew/whatsnew-fx62.html' elif show_61_whatsnew(version, oldversion): template = 'firefox/whatsnew/whatsnew-fx61.html' elif show_60_whatsnew(version, oldversion): template = 'firefox/whatsnew/whatsnew-fx60.html' elif show_59_whatsnew(version, oldversion): template = 'firefox/whatsnew/whatsnew-fxa.html' elif show_57_whatsnew(version, oldversion): # locale-specific templates don't seem to work for the default locale if locale == 'en-US': template = 'firefox/whatsnew/fx57/whatsnew-57.en-US.html' # locale-specific templates for de, en-GB, es-AR, es-CL, es-ES, es-MX, # fr, id, pl, pt-BR, ru, zh-CN, and zh-TW else: template = 'firefox/whatsnew/fx57/whatsnew-57.html' else: template = 'firefox/whatsnew/index.html' # return a list to conform with original intention return [template]
def home(request): locale = l10n_utils.get_locale(request) if lang_file_is_active('mozorg/home/index-quantum', locale) and switch('firefox-57-release'): template = 'mozorg/home/home-quantum.html' elif locale == 'en-US': template = 'mozorg/home/home-new.html' else: template = 'mozorg/home/home.html' return l10n_utils.render(request, template)
def send_tabs(request): if switch('firefox-57-release'): template = 'firefox/features/quantum/send-tabs.html' else: locale = l10n_utils.get_locale(request) exp = request.GET.get('v') if locale.startswith('en') and exp in ['a', 'b']: template = 'firefox/features/send-tabs-{0}.html'.format(exp) else: template = 'firefox/features/send-tabs.html' return l10n_utils.render(request, template)
def get_template_names(self): locale = l10n_utils.get_locale(self.request) version = self.kwargs.get('version') or '' oldversion = self.request.GET.get('oldversion', '') # old versions of Firefox sent a prefixed version if oldversion.startswith('rv:'): oldversion = oldversion[3:] channel = detect_channel(version) if channel == 'alpha': if show_57_dev_whatsnew(version): template = 'firefox/developer/whatsnew.html' else: template = 'firefox/dev-whatsnew.html' elif channel == 'nightly': template = 'firefox/nightly_whatsnew.html' elif locale == 'id': if switch('firefox_lite_whatsnew'): template = 'firefox/whatsnew/index-lite.id.html' else: template = 'firefox/whatsnew/index.id.html' elif locale == 'zh-TW' and not version.startswith('64.'): template = 'firefox/whatsnew/index.zh-TW.html' elif version.startswith('65.'): template = 'firefox/whatsnew/whatsnew-fx65.html' elif version.startswith('64.'): template = 'firefox/whatsnew/fx64/whatsnew-fx64.html' elif version.startswith('63.'): template = 'firefox/whatsnew/whatsnew-fx63.html' elif show_62_whatsnew(version, oldversion): template = 'firefox/whatsnew/whatsnew-fx62.html' elif show_61_whatsnew(version, oldversion): template = 'firefox/whatsnew/whatsnew-fx61.html' elif show_60_whatsnew(version, oldversion): template = 'firefox/whatsnew/whatsnew-fx60.html' elif show_59_whatsnew(version, oldversion): template = 'firefox/whatsnew/whatsnew-fxa.html' elif show_57_whatsnew(version, oldversion): # locale-specific templates don't seem to work for the default locale if locale == 'en-US': template = 'firefox/whatsnew/fx57/whatsnew-57.en-US.html' # locale-specific templates for de, en-GB, es-AR, es-CL, es-ES, es-MX, # fr, id, pl, pt-BR, ru, zh-CN, and zh-TW else: template = 'firefox/whatsnew/fx57/whatsnew-57.html' else: template = 'firefox/whatsnew/index.html' # return a list to conform with original intention return [template]
def get_template_names(self): locale = l10n_utils.get_locale(self.request) version = self.kwargs.get('version') or '' oldversion = self.request.GET.get('oldversion', '') # old versions of Firefox sent a prefixed version if oldversion.startswith('rv:'): oldversion = oldversion[3:] channel = detect_channel(version) if channel == 'nightly': template = 'firefox/nightly/whatsnew.html' elif channel == 'developer': if show_57_dev_whatsnew(version): template = 'firefox/developer/whatsnew.html' else: template = 'firefox/whatsnew/index.html' elif version.startswith('81.') and ftl_file_is_active( 'firefox/whatsnew/whatsnew-fx81'): template = 'firefox/whatsnew/whatsnew-fx81.html' elif version.startswith('80.') and ftl_file_is_active( 'firefox/whatsnew/whatsnew-fx80'): template = 'firefox/whatsnew/whatsnew-fx80.html' elif version.startswith('79.') and ftl_file_is_active( 'firefox/whatsnew/whatsnew-fx79'): template = 'firefox/whatsnew/whatsnew-fx79.html' elif version.startswith('78.'): template = 'firefox/whatsnew/index.html' elif version.startswith('77.') and lang_file_is_active( 'firefox/whatsnew_77', locale): # YouTube is blocked in China so zh-CN gets an alternative, self-hosted video. # If we run into bandwidth trouble we can turn the video off and zh-CN falls back to the 76 page. if locale == 'zh-CN' and not switch( 'firefox-whatsnew77-video-zhCN'): template = 'firefox/whatsnew/whatsnew-fx76.html' else: template = 'firefox/whatsnew/whatsnew-fx77.html' elif version.startswith('76.') and lang_file_is_active( 'firefox/whatsnew_76', locale): template = 'firefox/whatsnew/whatsnew-fx76.html' else: if show_default_account_whatsnew(version) and ftl_file_is_active( 'firefox/whatsnew/whatsnew-account'): template = 'firefox/whatsnew/index-account.html' else: template = 'firefox/whatsnew/index.html' # return a list to conform with original intention return [template]
def switch(name): """A template helper that replaces waffle * All calls default to True when DEV setting is True. * If the env var is explicitly false it will be false even when DEV = True. * Otherwise the call is False by default and True is a specific env var exists and is truthy. For example: {% if switch('dude-and-walter') %} would check for an environment variable called `SWITCH_DUDE_AND_WALTER`. The string from the `switch()` call is converted to uppercase and dashes replaced with underscores. """ return waffle.switch(name)
def get_template_names(self): locale = l10n_utils.get_locale(self.request) trailhead_locales = ['en-US', 'en-CA', 'en-GB', 'de', 'fr'] version = self.kwargs.get('version') or '' oldversion = self.request.GET.get('oldversion', '') # old versions of Firefox sent a prefixed version if oldversion.startswith('rv:'): oldversion = oldversion[3:] channel = detect_channel(version) if channel == 'nightly': template = 'firefox/nightly_whatsnew.html' elif channel == 'alpha': if version.startswith('68.') and switch('dev_whatsnew_68'): template = 'firefox/developer/whatsnew-fx68.html' elif show_57_dev_whatsnew(version): template = 'firefox/developer/whatsnew.html' else: template = 'firefox/dev-whatsnew.html' elif channel == 'beta': if version.startswith('68.'): template = 'firefox/whatsnew/beta/whatsnew-fx68.html' else: template = 'firefox/whatsnew/index.html' elif locale == 'id': template = 'firefox/whatsnew/index-lite.id.html' elif locale == 'zh-TW' and not version.startswith('64.'): template = 'firefox/whatsnew/index.zh-TW.html' elif version.startswith('67.0.') and locale in trailhead_locales: template = 'firefox/whatsnew/whatsnew-fx67.0.5.html' elif version.startswith('67.'): template = 'firefox/whatsnew/whatsnew-fx67.html' elif version.startswith('66.'): template = 'firefox/whatsnew/whatsnew-fx66.html' elif version.startswith('65.'): template = 'firefox/whatsnew/whatsnew-fx65.html' elif version.startswith('64.'): template = 'firefox/whatsnew/fx64/whatsnew-fx64.html' elif version.startswith('63.'): template = 'firefox/whatsnew/whatsnew-fx63.html' else: template = 'firefox/whatsnew/index.html' # return a list to conform with original intention return [template]
def get_template_names(self): variant = self.request.GET.get('v', None) locale = l10n_utils.get_locale(self.request) # ensure variant matches pre-defined value if variant not in self.variations: variant = None if locale == 'en-US' and variant: template = 'firefox/new/trailhead/exp-thanks.html' elif ftl_file_is_active('firefox/new/desktop') and switch( 'new-redesign'): template = 'firefox/new/desktop/thanks.html' else: template = 'firefox/new/trailhead/thanks.html' return [template]
def firefox_home(request): locale = l10n_utils.get_locale(request) variant = request.GET.get('v', None) newsletter_locales = ['en-US', 'en-GB', 'en-CA', 'en-ZA', 'fr', 'de'] show_newsletter = switch('firefox_pre_download_newsletter') and locale in newsletter_locales # ensure variant matches pre-defined value if variant not in ['a', 'b']: # place expected ?v= values in this list variant = None if locale == 'en-US' and variant == 'b': template = 'firefox/home/index-b.html' else: template = 'firefox/home/index.html' return l10n_utils.render(request, template, {'show_newsletter': show_newsletter})
def get_template_names(self): locale = l10n_utils.get_locale(self.request) country = get_country_from_request(self.request) variant = self.request.GET.get("v", None) experience = self.request.GET.get("xv", None) # ensure variant matches pre-defined value if variant not in self.variations: variant = None if country == "RU" and locale == "ru" and switch("firefox-yandex"): template = "firefox/new/desktop/download_yandex.html" elif ftl_file_is_active("firefox/new/desktop") and experience != "basic": template = "firefox/new/desktop/download.html" else: template = "firefox/new/basic/base_download.html" return [template]
def new(request): # Remove legacy query parameters (Bug 1236791) if request.GET.get('product', None) or request.GET.get('os', None): return HttpResponsePermanentRedirect(reverse('firefox.new')) scene = request.GET.get('scene', None) # note: v and xv params only allow a-z, A-Z, 0-9, -, and _ characters experience = request.GET.get('xv', None) variant = request.GET.get('v', None) locale = l10n_utils.get_locale(request) # ensure variant matches pre-defined value if variant not in ['a', 'b']: # place expected ?v= values in this list variant = None if scene == '2': # send to new permanent scene2 URL (bug 1438302) thanks_url = reverse('firefox.download.thanks') query_string = request.META.get('QUERY_STRING', '') if query_string: thanks_url = '?'.join( [thanks_url, force_text(query_string, errors='ignore')]) return HttpResponsePermanentRedirect(thanks_url) # if no/incorrect scene specified, show scene 1 else: if locale == 'ru' and switch('firefox-yandex'): template = 'firefox/new/yandex/scene1.html' elif lang_file_is_active('firefox/new/trailhead', locale): template = 'firefox/new/trailhead/download.html' else: template = 'firefox/new/scene1.html' # no harm done by passing 'v' to template, even when no experiment is running # (also makes tests easier to maintain by always sending a context) return l10n_utils.render(request, template, { 'experience': experience, 'v': variant })
def firefox_accounts(request): locale = l10n_utils.get_locale(request) # get localized blog post URL for 2019 page promise_query = ( '?utm_source=www.mozilla.org&utm_medium=referral&utm_campaign=accounts-trailhead' '&utm_content=accounts-value&utm_term=respect-you-deserve') promise_url = PROMISE_BLOG_URLS.get(locale, PROMISE_BLOG_URLS['en-US']) context = { 'promise_url': promise_url + promise_query, } if lang_file_is_active('firefox/accounts-2019', locale) and switch('firefox_accounts_trailhead'): template_name = 'firefox/accounts-2019.html' elif lang_file_is_active('firefox/accounts-2018', locale): template_name = 'firefox/accounts-2018.html' else: template_name = 'firefox/accounts.html' return l10n_utils.render(request, template_name, context)
def switch(cxt, name, locales=None): """A template helper that replaces waffle * All calls default to True when DEV setting is True (for the listed locales). * If the env var is explicitly false it will be false even when DEV = True. * Otherwise the call is False by default and True is a specific env var exists and is truthy. For example: {% if switch('dude-and-walter') %} would check for an environment variable called `SWITCH_DUDE_AND_WALTER`. The string from the `switch()` call is converted to uppercase and dashes replaced with underscores. If the `locales` argument is a list of locales then it will only check the switch in those locales, and return False otherwise. The `locales` argument could also contain a "locale group", which is a list of locales for a prefix (e.g. "en" expands to "en-US, en-GB, en-ZA"). """ if locales: if cxt['LANG'] not in expand_locale_groups(locales): return False return waffle.switch(name)
def new(request): # Remove legacy query parameters (Bug 1236791) if request.GET.get('product', None) or request.GET.get('os', None): return HttpResponsePermanentRedirect(reverse('firefox.new')) scene = request.GET.get('scene', None) # note: v and xv params only allow a-z, A-Z, 0-9, -, and _ charcaters experience = request.GET.get('xv', None) variant = request.GET.get('v', None) locale = l10n_utils.get_locale(request) # ensure variant matches pre-defined value if variant not in ['a', 'b']: # place expected ?v= values in this list variant = None if scene == '2': # send to new permanent scene2 URL (bug 1438302) thanks_url = reverse('firefox.download.thanks') query_string = request.META.get('QUERY_STRING', '') if query_string: thanks_url = '?'.join([thanks_url, force_text(query_string, errors='ignore')]) return HttpResponsePermanentRedirect(thanks_url) # if no/incorrect scene specified, show scene 1 else: if locale == 'ru' and switch('firefox-yandex'): template = 'firefox/new/yandex/scene1.html' elif lang_file_is_active('firefox/new/trailhead', locale): template = 'firefox/new/trailhead/download.html' else: template = 'firefox/new/scene1.html' # no harm done by passing 'v' to template, even when no experiment is running # (also makes tests easier to maintain by always sending a context) return l10n_utils.render(request, template, {'experience': experience, 'v': variant})
def test_switch_helper(config_mock): waffle.switch('dude-and-walter') config_mock.assert_called_with('DUDE_AND_WALTER', namespace='SWITCH', default=str(settings.DEV), parser=bool)
def oauth_fxa_error(request): if switch('firefox_concert_series'): return l10n_utils.render(request, 'mozorg/oauth/fxa-error.html') else: return HttpResponseRedirect(reverse('mozorg.home'))
def oauth_fxa(request): """ Acts as an OAuth relier for Firefox Accounts. Currently specifically tuned to handle the OAuth flow for the Firefox Concert Series (Q4 2018). If additional OAuth flows are required in the future, please refactor this method. """ if not switch('firefox_concert_series'): return HttpResponseRedirect(reverse('mozorg.home')) # expected state should be in user's cookies stateExpected = request.COOKIES.get('fxaOauthState', None) # provided state passed back from FxA - these state values should match stateProvided = request.GET.get('state', None) # code must be present - is in redirect querystring from FxA code = request.GET.get('code', None) error = False cookie_age = 86400 # 1 day # ensure all the data we need is present and valid if not (stateExpected and stateProvided and code): error = True elif stateExpected != stateProvided: error = True else: token = get_fxa_oauth_token(code) if not token: error = True else: email = get_fxa_profile_email(token) if not email: error = True else: # add email to mailing list # check for Firefox include_re = re.compile(r'\bFirefox\b', flags=re.I) exclude_re = re.compile(r'\b(Camino|Iceweasel|SeaMonkey)\b', flags=re.I) value = request.META.get('HTTP_USER_AGENT', '') isFx = bool(include_re.search(value) and not exclude_re.search(value)) # add user to mailing list for future concert updates rsvp_ok = fxa_concert_rsvp(email, isFx) if not rsvp_ok: error = True if error: # send user to a custom error page response = HttpResponseRedirect(reverse('mozorg.oauth.fxa-error')) else: # send user back to the concerts page response = HttpResponseRedirect(reverse('firefox.concerts')) response.set_cookie('fxaOauthVerified', True, max_age=cookie_age, httponly=False) return response
def get_bouncer_url(self, platform): return self.sha1_bouncer_url if not switch('disable-sha1-downloads') and platform == 'winsha1' else self.bouncer_url
def firefox_concerts(request): if switch('firefox_concert_series'): return l10n_utils.render(request, 'firefox/concerts.html') else: return HttpResponseRedirect(reverse('firefox'))
def new(request): # Remove legacy query parameters (Bug 1236791) if request.GET.get('product', None) or request.GET.get('os', None): return HttpResponsePermanentRedirect(reverse('firefox.new')) scene = request.GET.get('scene', None) # note: v and xv params only allow a-z, A-Z, 0-9, -, and _ charcaters experience = request.GET.get('xv', None) variant = request.GET.get('v', None) locale = l10n_utils.get_locale(request) # ensure variant matches pre-defined value if variant not in ['a', 'b', 'c', 'd', 'e', 'f']: # place expected ?v= values in this list variant = None if scene == '2': # send to new permanent scene2 URL (bug 1438302) thanks_url = reverse('firefox.download.thanks') query_string = request.META.get('QUERY_STRING', '') if query_string: thanks_url = '?'.join([thanks_url, force_text(query_string, errors='ignore')]) return HttpResponsePermanentRedirect(thanks_url) # if no/incorrect scene specified, show scene 1 else: if locale == 'de': if experience == 'berlin': template = 'firefox/campaign/berlin/scene1.html' elif experience == 'aus-gruenden': template = 'firefox/campaign/berlin/scene1-aus-gruenden.html' elif experience == 'herz': template = 'firefox/campaign/berlin/scene1-herz.html' elif experience == 'geschwindigkeit': template = 'firefox/campaign/berlin/scene1-gesch.html' elif experience == 'privatsphare': template = 'firefox/campaign/berlin/scene1-privat.html' elif experience == 'auf-deiner-seite': template = 'firefox/campaign/berlin/scene1-auf-deiner-seite.html' elif variant in ['a', 'b', 'c']: template = 'firefox/new/features/index.de-{}.html'.format(variant) else: template = 'firefox/new/scene1.html' elif switch('firefox-yandex') and locale == 'ru': template = 'firefox/new/yandex/scene1.html' elif locale == 'en-GB': if variant in ['a', 'b', 'c']: template = 'firefox/new/features/index.en-GB-{}.html'.format(variant) else: template = 'firefox/new/scene1.html' elif locale == 'en-US': if experience == 'betterbrowser': template = 'firefox/campaign/better-browser/scene1.html' elif experience == 'safari': template = 'firefox/campaign/compare/scene1-safari.html' elif experience == 'edge': template = 'firefox/campaign/compare/scene1-edge.html' else: template = 'firefox/new/scene1.html' else: template = 'firefox/new/scene1.html' # no harm done by passing 'v' to template, even when no experiment is running # (also makes tests easier to maintain by always sending a context) return l10n_utils.render(request, template, {'experience': experience, 'v': variant})
def test_switch_helper(config_mock): waffle.switch('dude-and-walter') config_mock.assert_called_with('SWITCH_DUDE_AND_WALTER', default=settings.DEV, cast=bool)
# 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/. from bedrock.base.waffle import switch from bedrock.mozorg.util import page from bedrock.redirects.util import redirect SOM_2015_ENABLED = switch('som-2015') SOM_REDIRECT = ('foundation.annualreport.2015.index' if SOM_2015_ENABLED else 'foundation.annualreport.2014.index') urlpatterns = ( page('', 'foundation/index.html'), page('about', 'foundation/about.html'), page('issues', 'foundation/issues.html'), page('advocacy', 'foundation/advocacy.html'), page('leadership-network', 'foundation/leadership-network.html'), # Bug 1317727 /foundation/annualreport/2015/ redirect(r'^annualreport/$', SOM_REDIRECT, name='foundation.annualreport', locale_prefix=False), # Older annual report financial faqs - these are linked from blog posts # was e.g.: http://www.mozilla.org/foundation/documents/mozilla-2008-financial-faq.html page('documents/mozilla-2006-financial-faq', 'foundation/documents/mozilla-2006-financial-faq.html'), page('documents/mozilla-2007-financial-faq', 'foundation/documents/mozilla-2007-financial-faq.html'), page('documents/mozilla-2008-financial-faq', 'foundation/documents/mozilla-2008-financial-faq.html'), # ported from PHP in Bug 960689
def existing(request, token=None): """Manage subscriptions. If token is provided, user can manage their existing subscriptions, to subscribe, unsubscribe, change email or language preferences, etc. If no token is provided, user can fill in their email and language preferences and sign up for newsletters. @param HTTPRequest request: Django request object @param string token: A UUID that identifies this user to the backend. It's sent to users in each newsletter as part of a link to this page, so they can manage their subscriptions without needing an account somewhere with userid & password. """ locale = getattr(request, 'locale', 'en-US') if not token: return redirect(reverse('newsletter.recovery')) if not UUID_REGEX.match(token): # Bad token messages.add_message(request, messages.ERROR, bad_token) # Redirect to the recovery page return redirect(reverse('newsletter.recovery')) if waffle.switch('newsletter-maintenance-mode'): return l10n_utils.render(request, 'newsletter/existing.html') unsub_parm = None # Example user: # # {u'lang': u'en', # u'format': u'H', # u'country': u'us', # u'newsletters': [u'firefox-tips', u'mobile'], # u'created-date': u'1/30/2013 12:46:05 PM', # u'token': u'some-uuid', # u'email': u'*****@*****.**' # } user_exists = False if token: try: user = basket.user(token) except basket.BasketNetworkException: # Something wrong with basket backend, no point in continuing, # we'd probably fail to subscribe them anyway. log.exception("Basket timeout") messages.add_message(request, messages.ERROR, general_error) return l10n_utils.render(request, 'newsletter/existing.html') except basket.BasketException as e: log.exception("FAILED to get user from token (%s)", e.desc) else: user_exists = True if not user_exists: # Bad or no token messages.add_message(request, messages.ERROR, bad_token) # Redirect to the recovery page return redirect(reverse('newsletter.recovery')) # Get the newsletter data - it's a dictionary of dictionaries newsletter_data = utils.get_newsletters() # Figure out which newsletters to display, and whether to show them # as already subscribed. initial = [] for newsletter, data in newsletter_data.iteritems(): # Only show a newsletter if it has ['active'] == True and # ['show'] == True or the user is already subscribed if not data.get('active', False): continue if data.get('show', False) or newsletter in user['newsletters']: langs = data['languages'] nstrings = NEWSLETTER_STRINGS.get(newsletter) if nstrings: title = nstrings['title'] description = nstrings.get('description', u'') else: # Firefox Marketplace for Desktop/Android/Firefox OS should be # shorten in the titles title = _(data['title'].replace('Firefox Marketplace for ', '')) description = _(data['description']) form_data = { 'title': Markup(title), 'subscribed_radio': newsletter in user['newsletters'], 'subscribed_check': newsletter in user['newsletters'], 'newsletter': newsletter, 'description': Markup(description), 'english_only': len(langs) == 1 and langs[0].startswith('en'), } if 'order' in data: form_data['order'] = data['order'] initial.append(form_data) # Sort by 'order' field if we were given it; otherwise, by title if initial: keyfield = 'order' if 'order' in initial[0] else 'title' initial.sort(key=itemgetter(keyfield)) NewsletterFormSet = formset_factory(NewsletterForm, extra=0, max_num=len(initial)) if request.method == 'POST': form_kwargs = {} # Temporary form so we can see if they checked 'remove_all'. If # they did, no point in validating the newsletters formset and it would # look dumb to complain about it. form = ManageSubscriptionsForm(locale, data=request.POST, initial=user) remove_all = form.is_valid() and form.cleaned_data['remove_all'] formset_is_valid = False if remove_all: # We don't care about the newsletter formset formset_is_valid = True # Make an initialized one in case we fall through to the bottom formset = NewsletterFormSet(initial=initial) else: # We do need to validate the newsletter formset formset = NewsletterFormSet(request.POST, initial=initial) # Set `newsletters` to the list of newsletters they want. # After this, we don't need the formset anymore. newsletters = None if formset.is_valid(): formset_is_valid = True # What newsletters do they say they want to be subscribed to? newsletters = set([subform.cleaned_data['newsletter'] for subform in formset if (subform.cleaned_data['subscribed_radio'] or subform.cleaned_data['subscribed_check'])]) form_kwargs['newsletters'] = newsletters form = ManageSubscriptionsForm(locale, data=request.POST, initial=user, **form_kwargs) if formset_is_valid and form.is_valid(): data = form.cleaned_data # Update their format and locale information, if it has changed. # Also pass their updated list of newsletters they want to be # subscribed to, for basket to implement. kwargs = {} for k in ['lang', 'format', 'country']: if user[k] != data[k]: kwargs[k] = data[k] if not remove_all: kwargs['newsletters'] = ",".join(newsletters) if kwargs: try: basket.update_user(token, **kwargs) except basket.BasketException: log.exception("Error updating user in basket") messages.add_message( request, messages.ERROR, general_error ) return l10n_utils.render(request, 'newsletter/existing.html') # If they chose to remove all, tell basket that they've opted out if remove_all: try: basket.unsubscribe(token, user['email'], optout=True) except (basket.BasketException, requests.Timeout): log.exception("Error updating subscriptions in basket") messages.add_message( request, messages.ERROR, general_error ) return l10n_utils.render(request, 'newsletter/existing.html') # We need to pass their token to the next view url = reverse('newsletter.updated') \ + "?unsub=%s&token=%s" % (UNSUB_UNSUBSCRIBED_ALL, token) return redirect(url) # We're going to redirect, so the only way to tell the next # view that we should display the welcome message in the # template is to modify the URL url = reverse('newsletter.updated') if unsub_parm: url += "?unsub=%s" % unsub_parm return redirect(url) # FALL THROUGH so page displays errors else: form = ManageSubscriptionsForm( locale, initial=user ) formset = NewsletterFormSet(initial=initial) # For the template, we want a dictionary whose keys are language codes # and each value is the list of newsletter keys that are available in # that language code. newsletter_languages = defaultdict(list) for newsletter, data in newsletter_data.iteritems(): for lang in data['languages']: newsletter_languages[lang].append(newsletter) newsletter_languages = mark_safe(json.dumps(newsletter_languages)) # We also want a list of the newsletters the user is already subscribed to already_subscribed = mark_safe(json.dumps(user['newsletters'])) context = { 'did_confirm': request.GET.get('confirm', None) == '1', 'form': form, 'formset': formset, 'newsletter_languages': newsletter_languages, 'newsletters_subscribed': already_subscribed, 'email': user['email'], } return l10n_utils.render(request, 'newsletter/existing.html', context)
def new(request): # Remove legacy query parameters (Bug 1236791) if request.GET.get('product', None) or request.GET.get('os', None): return HttpResponsePermanentRedirect(reverse('firefox.new')) scene = request.GET.get('scene', None) experience = request.GET.get('xv', None) variant = request.GET.get('v', None) locale = l10n_utils.get_locale(request) # ensure variant matches pre-defined value if variant not in ['a', 'b', 'c', 'd', 'e', 'f', '1', '2']: # place expected ?v= values in this list variant = None if scene == '2': # send to new permanent scene2 URL (bug 1438302) thanks_url = reverse('firefox.download.thanks') query_string = request.META.get('QUERY_STRING', '') if query_string: thanks_url = '?'.join([thanks_url, force_text(query_string, errors='ignore')]) return HttpResponsePermanentRedirect(thanks_url) # if no/incorrect scene specified, show scene 1 else: if lang_file_is_active('firefox/new/wait-face', locale) and experience == 'waitface': template = 'firefox/new/wait-face/scene1.html' elif lang_file_is_active('firefox/new/reggiewatts', locale) and experience == 'reggiewatts': template = 'firefox/new/reggie-watts/scene1.html' elif locale == 'de': if experience == 'berlin': template = 'firefox/new/berlin/scene1.html' elif experience == 'aus-gruenden': template = 'firefox/new/berlin/scene1-aus-gruenden.html' elif experience == 'herz': template = 'firefox/new/berlin/scene1-herz.html' elif experience == 'geschwindigkeit': template = 'firefox/new/berlin/scene1-gesch.html' elif experience == 'privatsphare': template = 'firefox/new/berlin/scene1-privat.html' elif experience == 'auf-deiner-seite': template = 'firefox/new/berlin/scene1-auf-deiner-seite.html' else: template = 'firefox/new/scene1.html' elif switch('firefox-yandex') and locale == 'ru': template = 'firefox/new/yandex/scene1.html' elif locale == 'en-US': if experience in ['portland', 'forgood']: template = 'firefox/new/portland/scene1.html' elif experience in ['portland-fast', 'fast']: template = 'firefox/new/portland/scene1-fast.html' elif experience in ['portland-safe', 'safe']: template = 'firefox/new/portland/scene1-safe.html' elif experience == 'betterbrowser': template = 'firefox/new/better-browser/scene1.html' elif experience == 'safari': if variant == 'a': template = 'firefox/new/scene1.html' elif variant == '2': template = 'firefox/new/compare/scene1-safari-2.html' else: template = 'firefox/new/compare/scene1-safari-1.html' elif experience == 'chrome': if variant == 'a': template = 'firefox/new/scene1.html' elif variant == '2': template = 'firefox/new/compare/scene1-chrome-2.html' else: template = 'firefox/new/compare/scene1-chrome-1.html' elif experience == 'edge': if variant == 'a': template = 'firefox/new/scene1.html' elif variant == '2': template = 'firefox/new/compare/scene1-edge-2.html' else: template = 'firefox/new/compare/scene1-edge-1.html' else: template = 'firefox/new/scene1.html' else: template = 'firefox/new/scene1.html' # no harm done by passing 'v' to template, even when no experiment is running # (also makes tests easier to maintain by always sending a context) return l10n_utils.render(request, template, {'experience': experience})