Exemplo n.º 1
0
 def setUp(self):
     self.webapp = Webapp.objects.get(pk=337141)
     self.request = RequestFactory().get('/')
     RegionMiddleware().process_request(self.request)
     self.reindex(Webapp, 'webapp')
     self.indexer = S(WebappIndexer).filter(id=337141).execute().objects[0]
     self.serializer = SimpleESAppSerializer(self.indexer,
         context={'request': self.request})
Exemplo n.º 2
0
 def region_for(self, region):
     req = self.factory.get('/', ({} if region is None else
                                  {'region': region}))
     req.API = True
     req.LANG = ''
     req.user = self.user
     req.amo_user = self.profile
     RegionMiddleware().process_request(req)
     ACLMiddleware().process_request(req)
     return self.resource.get_region_from_request(req)
Exemplo n.º 3
0
 def setUp(self):
     self.webapp = Webapp.objects.get(pk=337141)
     self.request = RequestFactory().get('/')
     self.request.user = AnonymousUser()
     RegionMiddleware().process_request(self.request)
     self.reindex(Webapp)
     self.indexer = WebappIndexer.search().filter(
         'term', id=self.webapp.id).execute().hits[0]
     self.serializer = SimpleESAppSerializer(
         self.indexer, context={'request': self.request})
Exemplo n.º 4
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.º 5
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_persona = True
    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 request.GET.get('nativepersona') or has_sim_info_in_query:
            # If we received SIM information or nativepersona was passed, we
            # don't include the persona shim, we consider that we are dealing
            # with a Firefox OS device that has native support for persona.
            include_persona = False
        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_persona = False
        include_splash = True

    if waffle.switch_is_active('firefox-accounts'):
        # 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.
        include_persona = False
        fxa_auth_state, fxa_auth_url = fxa_auth_info()
        site_settings = {
            'fxa_auth_state': fxa_auth_state,
            'fxa_auth_url': fxa_auth_url
        }
    else:
        site_settings = {
            'persona_unverified_issuer': settings.BROWSERID_DOMAIN,
        }

    site_settings['fxa_css_path'] = settings.FXA_CSS_PATH

    ctx = {
        'BUILD_ID': BUILD_ID,
        'appcache': repo in settings.COMMONPLACE_REPOS_APPCACHED,
        'include_persona': include_persona,
        '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.º 6
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.º 7
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)