Exemplo n.º 1
0
def site_config(request):
    """
    A resource that is designed to be exposed externally and contains
    settings or waffle flags that might be relevant to the client app.
    """
    def serialized_data(cls):
        as_list = cls(cls.Meta.model.objects.all().order_by('name'),
                      many=True).data
        return dict((d['name'], d) for d in as_list)

    # For Commonplace, we don't need settings or version, we just want a simple
    # list of active waffle switches, we don't even care about flags.
    if request.GET.get('serializer') == 'commonplace':
        data = {
            'waffle': {
                'switches':
                list(
                    waffle.models.Switch.objects.filter(
                        active=True).values_list('name', flat=True))
            }
        }
    else:
        data = {
            'settings': get_settings(),
            'version': getattr(settings, 'BUILD_ID_JS', ''),
            'waffle': {
                'switches': serialized_data(SwitchSerializer),
                'flags': serialized_data(FlagSerializer)
            }
        }

    # Always include FxA info, all projects need it.
    fxa_auth_state, fxa_auth_url = fxa_auth_info()
    data['fxa'] = {
        'fxa_auth_state': fxa_auth_state,
        'fxa_auth_url': fxa_auth_url
    }
    return Response(data)
Exemplo n.º 2
0
def site_config(request):
    """
    A resource that is designed to be exposed externally and contains
    settings or waffle flags that might be relevant to the client app.
    """
    def serialized_data(cls):
        as_list = cls(cls.Meta.model.objects.all().order_by('name'),
                      many=True).data
        return dict((d['name'], d) for d in as_list)

    # For Commonplace, we don't need settings or version, we just want a simple
    # list of active waffle switches, we don't even care about flags.
    if request.GET.get('serializer') == 'commonplace':
        data = {
            'waffle': {
                'switches': list(
                    waffle.models.Switch.objects.filter(active=True)
                                        .values_list('name', flat=True))
            }
        }
    else:
        data = {
            'settings': get_settings(),
            'version': getattr(settings, 'BUILD_ID_JS', ''),
            'waffle': {
                'switches': serialized_data(SwitchSerializer),
                'flags': serialized_data(FlagSerializer)
            }
        }

    # Always include FxA info, all projects need it.
    fxa_auth_state, fxa_auth_url = fxa_auth_info()
    data['fxa'] = {
        'fxa_auth_state': fxa_auth_state,
        'fxa_auth_url': fxa_auth_url
    }
    return Response(data)
Exemplo n.º 3
0
def commonplace(request, repo, **kwargs):
    """Serves the frontend single-page apps."""
    if repo not in settings.FRONTEND_REPOS:
        raise Http404

    BUILD_ID = get_build_id(repo)

    ua = request.META.get('HTTP_USER_AGENT', '').lower()

    include_splash = False
    detect_region_with_geoip = False
    if repo == 'fireplace':
        include_splash = True
        has_sim_info_in_query = ('mccs' in request.GET
                                 or ('mcc' in request.GET
                                     and 'mnc' in request.GET))
        if not has_sim_info_in_query:
            # If we didn't receive mcc/mnc, then use geoip to detect region,
            # enabling fireplace to avoid the consumer_info API call that it
            # does normally to fetch the region.
            detect_region_with_geoip = True

    fxa_auth_state, fxa_auth_url = fxa_auth_info()
    site_settings = {
        'dev_pay_providers': settings.DEV_PAY_PROVIDERS,
        'fxa_auth_state': fxa_auth_state,
        'fxa_auth_url': fxa_auth_url,
    }

    ctx = {
        'BUILD_ID': BUILD_ID,
        'LANG': request.LANG,
        'DIR': lang_dir(request.LANG),
        'include_splash': include_splash,
        'repo': repo,
        'robots': 'googlebot' in ua,
        'site_settings': site_settings,
        'newrelic_header': newrelic.agent.get_browser_timing_header,
        'newrelic_footer': newrelic.agent.get_browser_timing_footer,
    }

    if repo == 'fireplace':
        # For OpenGraph stuff.
        resolved_url = resolve(request.path)
        if resolved_url.url_name == 'detail':
            ctx = add_app_ctx(ctx, resolved_url.kwargs['app_slug'])

    ctx['waffle_switches'] = list(
        waffle.models.Switch.objects.filter(active=True).values_list(
            'name', flat=True))

    media_url = urlparse(settings.MEDIA_URL)
    if media_url.netloc:
        ctx['media_origin'] = media_url.scheme + '://' + media_url.netloc

    if detect_region_with_geoip:
        region_middleware = RegionMiddleware()
        ctx['geoip_region'] = region_middleware.region_from_request(request)

    if repo in settings.REACT_REPOS:
        return render(request, 'commonplace/index_react.html', ctx)
    elif repo in settings.COMMONPLACE_REPOS:
        return render(request, 'commonplace/index.html', ctx)
Exemplo n.º 4
0
def commonplace(request, repo, **kwargs):
    if repo not in settings.COMMONPLACE_REPOS:
        raise Http404

    BUILD_ID = get_build_id(repo)

    ua = request.META.get('HTTP_USER_AGENT', '').lower()

    include_splash = False
    detect_region_with_geoip = False
    if repo == 'fireplace':
        include_splash = True
        has_sim_info_in_query = ('mccs' in request.GET or
            ('mcc' in request.GET and 'mnc' in request.GET))
        if not has_sim_info_in_query:
            # If we didn't receive mcc/mnc, then use geoip to detect region,
            # enabling fireplace to avoid the consumer_info API call that it
            # does normally to fetch the region.
            detect_region_with_geoip = True
    elif repo == 'discoplace':
        include_splash = True

    # We never want to include persona shim if firefox accounts is enabled:
    # native fxa already provides navigator.id, and fallback fxa doesn't
    # need it.
    fxa_auth_state, fxa_auth_url = fxa_auth_info()
    site_settings = {
        'fxa_auth_state': fxa_auth_state,
        'fxa_auth_url': fxa_auth_url
    }

    site_settings['fxa_css_path'] = settings.FXA_CSS_PATH

    ctx = {
        'BUILD_ID': BUILD_ID,
        'appcache': repo in settings.COMMONPLACE_REPOS_APPCACHED,
        'include_persona': False,
        'include_splash': include_splash,
        'repo': repo,
        'robots': 'googlebot' in ua,
        'site_settings': site_settings,
        'newrelic_header': newrelic.agent.get_browser_timing_header,
        'newrelic_footer': newrelic.agent.get_browser_timing_footer,
    }

    if repo == 'fireplace':
        # For OpenGraph stuff.
        resolved_url = resolve(request.path)
        if resolved_url.url_name == 'detail':
            ctx = add_app_ctx(ctx, resolved_url.kwargs['app_slug'])

    ctx['waffle_switches'] = list(
        waffle.models.Switch.objects.filter(active=True)
                                    .values_list('name', flat=True))

    media_url = urlparse(settings.MEDIA_URL)
    if media_url.netloc:
        ctx['media_origin'] = media_url.scheme + '://' + media_url.netloc

    if detect_region_with_geoip:
        region_middleware = RegionMiddleware()
        ctx['geoip_region'] = region_middleware.region_from_request(request)

    return render(request, 'commonplace/index.html', ctx)
Exemplo n.º 5
0
def commonplace(request, repo, **kwargs):
    """Serves the frontend single-page apps."""
    if repo not in settings.FRONTEND_REPOS:
        raise Http404

    BUILD_ID = get_build_id(repo)

    ua = request.META.get('HTTP_USER_AGENT', '').lower()

    include_splash = False
    detect_region_with_geoip = False
    if repo == 'fireplace':
        include_splash = True
        has_sim_info_in_query = (
            'mccs' in request.GET or
            ('mcc' in request.GET and 'mnc' in request.GET))
        if not has_sim_info_in_query:
            # If we didn't receive mcc/mnc, then use geoip to detect region,
            # enabling fireplace to avoid the consumer_info API call that it
            # does normally to fetch the region.
            detect_region_with_geoip = True

    fxa_auth_state, fxa_auth_url = fxa_auth_info()
    site_settings = {
        'dev_pay_providers': settings.DEV_PAY_PROVIDERS,
        'fxa_auth_state': fxa_auth_state,
        'fxa_auth_url': fxa_auth_url,
    }

    ctx = {
        'BUILD_ID': BUILD_ID,
        'LANG': request.LANG,
        'langdir': lang_dir(request.LANG),
        'include_splash': include_splash,
        'repo': repo,
        'robots': 'googlebot' in ua,
        'site_settings': site_settings,
        'newrelic_header': newrelic.agent.get_browser_timing_header,
        'newrelic_footer': newrelic.agent.get_browser_timing_footer,
    }

    if repo == 'fireplace':
        # For OpenGraph stuff.
        resolved_url = resolve(request.path)
        if resolved_url.url_name == 'detail':
            ctx = add_app_ctx(ctx, resolved_url.kwargs['app_slug'])

    ctx['waffle_switches'] = list(
        waffle.models.Switch.objects.filter(active=True)
                                    .values_list('name', flat=True))

    media_url = urlparse(settings.MEDIA_URL)
    if media_url.netloc:
        ctx['media_origin'] = media_url.scheme + '://' + media_url.netloc

    if detect_region_with_geoip:
        region_middleware = RegionMiddleware()
        ctx['geoip_region'] = region_middleware.region_from_request(request)

    if repo == 'marketplace-tv-front-end':
        return render(request, 'commonplace/index_tv.html', ctx)
    elif repo in settings.REACT_REPOS:
        return render(request, 'commonplace/index_react.html', ctx)
    elif repo in settings.COMMONPLACE_REPOS:
        return render(request, 'commonplace/index.html', ctx)
Exemplo n.º 6
0
def commonplace(request, repo, **kwargs):
    if repo not in settings.COMMONPLACE_REPOS:
        raise Http404

    BUILD_ID = get_build_id(repo)

    ua = request.META.get('HTTP_USER_AGENT', '').lower()

    include_splash = False
    detect_region_with_geoip = False
    if repo == 'fireplace':
        include_splash = True
        has_sim_info_in_query = ('mccs' in request.GET
                                 or ('mcc' in request.GET
                                     and 'mnc' in request.GET))
        if not has_sim_info_in_query:
            # If we didn't receive mcc/mnc, then use geoip to detect region,
            # enabling fireplace to avoid the consumer_info API call that it
            # does normally to fetch the region.
            detect_region_with_geoip = True
    elif repo == 'discoplace':
        include_splash = True

    # We never want to include persona shim if firefox accounts is enabled:
    # native fxa already provides navigator.id, and fallback fxa doesn't
    # need it.
    fxa_auth_state, fxa_auth_url = fxa_auth_info()
    site_settings = {
        'fxa_auth_state': fxa_auth_state,
        'fxa_auth_url': fxa_auth_url
    }

    site_settings['fxa_css_path'] = settings.FXA_CSS_PATH

    ctx = {
        'BUILD_ID': BUILD_ID,
        'appcache': repo in settings.COMMONPLACE_REPOS_APPCACHED,
        'include_persona': False,
        'include_splash': include_splash,
        'repo': repo,
        'robots': 'googlebot' in ua,
        'site_settings': site_settings,
        'newrelic_header': newrelic.agent.get_browser_timing_header,
        'newrelic_footer': newrelic.agent.get_browser_timing_footer,
    }

    if repo == 'fireplace':
        # For OpenGraph stuff.
        resolved_url = resolve(request.path)
        if resolved_url.url_name == 'detail':
            ctx = add_app_ctx(ctx, resolved_url.kwargs['app_slug'])

    ctx['waffle_switches'] = list(
        waffle.models.Switch.objects.filter(active=True).values_list(
            'name', flat=True))

    media_url = urlparse(settings.MEDIA_URL)
    if media_url.netloc:
        ctx['media_origin'] = media_url.scheme + '://' + media_url.netloc

    if detect_region_with_geoip:
        region_middleware = RegionMiddleware()
        ctx['geoip_region'] = region_middleware.region_from_request(request)

    return render(request, 'commonplace/index.html', ctx)