Пример #1
0
def manifest(request):
    ctx = RequestContext(request)
    data = {
        "name": getattr(settings, "WEBAPP_MANIFEST_NAME", "Firefox Marketplace"),
        "description": "The Firefox Marketplace",
        "developer": {"name": "Mozilla", "url": "http://mozilla.org"},
        "icons": {
            # Using the default addon image until we get a marketplace logo.
            "128": media(ctx, "img/mkt/logos/128.png"),
            "64": media(ctx, "img/mkt/logos/64.png"),
            "32": media(ctx, "img/mkt/logos/32.png"),
        },
        "activities": {
            "marketplace-app": {"href": "/"},
            "marketplace-app-rating": {"href": "/"},
            "marketplace-category": {"href": "/"},
            "marketplace-search": {"href": "/"},
        },
    }
    if get_carrier():
        data["launch_path"] = urlparams("/", carrier=get_carrier())

    manifest_content = json.dumps(data)
    manifest_etag = hashlib.sha256(manifest_content).hexdigest()

    @etag(lambda r: manifest_etag)
    def _inner_view(request):
        response = HttpResponse(manifest_content, content_type="application/x-web-app-manifest+json")
        return response

    return _inner_view(request)
Пример #2
0
    def test_set_carrier_to_none_url(self):
        self.get('/telefonica/')
        self.get('/not-a-store')
        eq_(get_carrier(), None)

        self.get('/?carrier=telefonica')
        self.get('/?carrier=not-a-store')
        eq_(get_carrier(), None)
Пример #3
0
    def test_set_carrier_to_none_url(self):
        self.get('/telefonica/')
        self.get('/not-a-store')
        eq_(get_carrier(), None)

        self.get('/?carrier=telefonica')
        self.get('/?carrier=not-a-store')
        eq_(get_carrier(), None)
Пример #4
0
def manifest(request):
    ctx = RequestContext(request)
    data = {
        'name': getattr(settings, 'WEBAPP_MANIFEST_NAME',
                        'Firefox Marketplace'),
        'description': 'The Firefox Marketplace',
        'developer': {
            'name': 'Mozilla',
            'url': 'http://mozilla.org',
        },
        'icons': {
            # Using the default addon image until we get a marketplace logo.
            '128': media(ctx, 'img/mkt/logos/128.png'),
            '64': media(ctx, 'img/mkt/logos/64.png'),
            '32': media(ctx, 'img/mkt/logos/32.png'),
        },
        'activities': {
            'marketplace-app': {
                'href': '/'
            },
            'marketplace-app-rating': {
                'href': '/'
            },
            'marketplace-category': {
                'href': '/'
            },
            'marketplace-search': {
                'href': '/'
            },
        },
        'orientation': ['portrait-primary']
    }
    if settings.USE_APPCACHE:
        data['appcache_path'] = reverse('django_appcache.manifest')
    if get_carrier():
        data['launch_path'] = urlparams('/', carrier=get_carrier())

    manifest_content = json.dumps(data)
    manifest_etag = hashlib.md5(manifest_content).hexdigest()

    @etag(lambda r: manifest_etag)
    def _inner_view(request):
        response = HttpResponse(manifest_content,
                                mimetype='application/x-web-app-manifest+json')
        return response

    return _inner_view(request)
Пример #5
0
def manifest(request):
    ctx = RequestContext(request)
    for processor in get_standard_processors():
        ctx.update(processor(request))
    data = {
        'name': getattr(settings, 'WEBAPP_MANIFEST_NAME',
                        'Firefox Marketplace'),
        'description': 'The Firefox Marketplace',
        'developer': {
            'name': 'Mozilla',
            'url': 'http://mozilla.org',
        },
        'icons': {
            # Using the default addon image until we get a marketplace logo.
            '128': media(ctx, 'img/mkt/logos/128.png'),
            '64': media(ctx, 'img/mkt/logos/64.png'),
            '32': media(ctx, 'img/mkt/logos/32.png'),
        },
        'activities': {
            'marketplace-app': {
                'href': '/'
            },
            'marketplace-app-rating': {
                'href': '/'
            },
            'marketplace-category': {
                'href': '/'
            },
            'marketplace-search': {
                'href': '/'
            },
        }
    }
    if get_carrier():
        data['launch_path'] = urlparams('/', carrier=get_carrier())

    manifest_content = json.dumps(data)
    manifest_etag = hashlib.sha256(manifest_content).hexdigest()

    @etag(lambda r: manifest_etag)
    def _inner_view(request):
        response = HttpResponse(
            manifest_content,
            content_type='application/x-web-app-manifest+json')
        return response

    return _inner_view(request)
Пример #6
0
    def featured(cls, cat=None, region=None, limit=6, mobile=False,
                 gaia=False):
        FeaturedApp = models.get_model('zadmin', 'FeaturedApp')
        qs = (FeaturedApp.objects
              .filter(app__status=amo.STATUS_PUBLIC,
                      app__disabled_by_user=False)
              .order_by('-app__weekly_downloads'))
        qs = (qs.filter(start_date__lte=cls.now())
              | qs.filter(start_date__isnull=True))
        qs = (qs.filter(end_date__gte=cls.now())
              | qs.filter(end_date__isnull=True))

        if waffle.switch_is_active('disabled-payments') or not gaia:
            qs = qs.filter(app__premium_type__in=amo.ADDON_FREES)

        if isinstance(cat, list):
            qs = qs.filter(category__in=cat)
        else:
            qs = qs.filter(category=cat.id if cat else None)

        locale_qs = FeaturedApp.objects.none()
        worldwide_qs = FeaturedApp.objects.none()

        carrier = get_carrier()
        if carrier:
            qs = qs.filter(carriers__carrier=carrier)

        if gaia:
            qs = qs.filter(
                app__addondevicetype__device_type=amo.DEVICE_GAIA.id)
        elif mobile:
            qs = qs.filter(
                app__addondevicetype__device_type=amo.DEVICE_MOBILE.id)

        if region:
            excluded = cls.get_excluded_in(region)
            locale_qs = (qs.filter(regions__region=region.id)
                         .exclude(app__id__in=excluded))

            # Fill the empty spots with Worldwide-featured apps.
            if limit:
                empty_spots = limit - locale_qs.count()
                if empty_spots > 0 and region != mkt.regions.WORLDWIDE:
                    ww = mkt.regions.WORLDWIDE.id
                    worldwide_qs = (qs.filter(regions__region=ww)
                                    .exclude(id__in=[x.id for x in locale_qs])
                                    .exclude(app__id__in=excluded))[:limit]

        if limit:
            locale_qs = locale_qs[:limit]

        if worldwide_qs:
            combined = ([fa.app for fa in locale_qs] +
                        [fa.app for fa in worldwide_qs])
            return list(set(combined))[:limit]

        return [fa.app for fa in locale_qs]
Пример #7
0
 def process_response(self, request, response):
     if getattr(request, 'API', False) and response.status_code < 500:
         filters = (
             ('carrier', get_carrier() or ''),
             ('lang', request.LANG),
             ('pro', request.GET.get('pro', '')),
             ('region', request.REGION.slug),
         )
         response['API-Filter'] = urlencode(filters, doseq=True)
         patch_vary_headers(response, ['API-Filter'])
     return response
Пример #8
0
    def featured(self, cat=None, region=None, limit=9, mobile=False,
                 gaia=False, tablet=False):
        """
        Filters the QuerySet, removing FeaturedApp instances that should
        not be featured based on the passed criteria.

        If a region is defined and there are fewer than `limit` items
        remaining in the resultant queryset, the difference is populated by
        additional apps that are featured worldwide.
        """
        qs = self.active()
        Webapp = get_model('webapps', 'Webapp')

        excluded = Webapp.objects.none()
        if region:
            from mkt.webapps.models import get_excluded_in
            excluded = get_excluded_in(region.id)

        if waffle.switch_is_active('disabled-payments') or not gaia:
            qs = qs.filter(app__premium_type__in=amo.ADDON_FREES)

        qs = qs.for_category(cat)

        carrier = get_carrier()
        if carrier:
            qs = qs.for_carrier(carrier)

        if gaia:
            qs = qs.gaia()
        elif mobile:
            qs = qs.mobile()

        if tablet:
            qs = qs.tablet()

        qs_pre_region = qs._clone()

        if region:
            qs = qs.for_region(region).exclude(app__id__in=excluded)

            # Fill the empty spots with Worldwide-featured apps.
            if limit:
                empty_spots = limit - qs.count()
                if empty_spots > 0 and region != mkt.regions.WORLDWIDE:
                    qs |= (qs_pre_region.worldwide()
                           .exclude(id__in=[x.id for x in qs])
                           .exclude(app__id__in=excluded))

        if limit:
            qs = qs[:limit]

        return qs
Пример #9
0
def manifest(request):
    ctx = RequestContext(request)
    data = {
        'name': getattr(settings, 'WEBAPP_MANIFEST_NAME',
                        'Firefox Marketplace'),
        'description': 'The Firefox Marketplace',
        'developer': {
            'name': 'Mozilla',
            'url': 'http://mozilla.org',
        },
        'icons': {
            # Using the default addon image until we get a marketplace logo.
            '128': media(ctx, 'img/mkt/logos/128.png'),
            '64': media(ctx, 'img/mkt/logos/64.png'),
            '32': media(ctx, 'img/mkt/logos/32.png'),
        },
        'activities': {
            'marketplace-app': {'href': '/'},
            'marketplace-app-rating': {'href': '/'},
            'marketplace-category': {'href': '/'},
            'marketplace-search': {'href': '/'},
        },
        'orientation': ['portrait-primary']
    }
    if settings.USE_APPCACHE:
        data['appcache_path'] = reverse('django_appcache.manifest')
    if get_carrier():
        data['launch_path'] = urlparams('/', carrier=get_carrier())

    manifest_content = json.dumps(data)
    manifest_etag = hashlib.md5(manifest_content).hexdigest()

    @etag(lambda r: manifest_etag)
    def _inner_view(request):
        response = HttpResponse(manifest_content,
                                mimetype='application/x-web-app-manifest+json')
        return response

    return _inner_view(request)
Пример #10
0
def manifest(request):
    ctx = RequestContext(request)
    for processor in get_standard_processors():
        ctx.update(processor(request))
    data = {
        'name': getattr(settings, 'WEBAPP_MANIFEST_NAME',
                        'Firefox Marketplace'),
        'description': 'The Firefox Marketplace',
        'developer': {
            'name': 'Mozilla',
            'url': 'http://mozilla.org',
        },
        'icons': {
            # Using the default addon image until we get a marketplace logo.
            '128': media(ctx, 'img/mkt/logos/128.png'),
            '64': media(ctx, 'img/mkt/logos/64.png'),
            '32': media(ctx, 'img/mkt/logos/32.png'),
        },
        'activities': {
            'marketplace-app': {'href': '/'},
            'marketplace-app-rating': {'href': '/'},
            'marketplace-category': {'href': '/'},
            'marketplace-search': {'href': '/'},
        }
    }
    if get_carrier():
        data['launch_path'] = urlparams('/', carrier=get_carrier())

    manifest_content = json.dumps(data)
    manifest_etag = hashlib.sha256(manifest_content).hexdigest()

    @etag(lambda r: manifest_etag)
    def _inner_view(request):
        response = HttpResponse(
            manifest_content,
            content_type='application/x-web-app-manifest+json')
        return response

    return _inner_view(request)
Пример #11
0
 def process_response(self, request, response):
     if getattr(request, 'API', False) and response.status_code < 500:
         devices = []
         for device in ('GAIA', 'MOBILE', 'TABLET'):
             if getattr(request, device, False):
                 devices.append(device.lower())
         filters = (
             ('carrier', get_carrier() or ''),
             ('device', devices),
             ('lang', request.LANG),
             ('region', request.REGION.slug),
         )
         response['API-Filter'] = urlencode(filters, doseq=True)
         patch_vary_headers(response, ['API-Filter'])
     return response
Пример #12
0
    def featured(cls, cat=None, region=None, limit=6, gaia=False):
        FeaturedApp = models.get_model('zadmin', 'FeaturedApp')
        qs = (FeaturedApp.objects.filter(
            app__status=amo.STATUS_PUBLIC,
            app__disabled_by_user=False).order_by('-app__weekly_downloads'))
        qs = (qs.filter(start_date__lte=cls.now())
              | qs.filter(start_date__isnull=True))
        qs = (qs.filter(end_date__gte=cls.now())
              | qs.filter(end_date__isnull=True))

        if waffle.switch_is_active('disabled-payments') or not gaia:
            qs = qs.filter(app__premium_type__in=amo.ADDON_FREES)

        if isinstance(cat, list):
            qs = qs.filter(category__in=cat)
        else:
            qs = qs.filter(category=cat.id if cat else None)

        locale_qs = FeaturedApp.objects.none()
        worldwide_qs = FeaturedApp.objects.none()

        carrier = get_carrier()
        if carrier:
            qs = qs.filter(carriers__carrier=carrier)

        if region:
            excluded = cls.get_excluded_in(region)
            locale_qs = (qs.filter(regions__region=region.id).exclude(
                app__id__in=excluded))

            # Fill the empty spots with Worldwide-featured apps.
            if limit:
                empty_spots = limit - locale_qs.count()
                if empty_spots > 0 and region != mkt.regions.WORLDWIDE:
                    ww = mkt.regions.WORLDWIDE.id
                    worldwide_qs = (qs.filter(regions__region=ww).exclude(
                        id__in=[x.id for x in locale_qs]).exclude(
                            app__id__in=excluded))[:limit]

        if limit:
            locale_qs = locale_qs[:limit]

        if worldwide_qs:
            combined = ([fa.app for fa in locale_qs] +
                        [fa.app for fa in worldwide_qs])
            return list(set(combined))[:limit]

        return [fa.app for fa in locale_qs]
Пример #13
0
 def process_response(self, request, response):
     if getattr(request, 'API', False) and response.status_code < 500:
         devices = []
         for device in ('GAIA', 'MOBILE', 'TABLET'):
             if getattr(request, device, False):
                 devices.append(device.lower())
         filters = (
             ('carrier', get_carrier() or ''),
             ('device', devices),
             ('lang', request.LANG),
             ('pro', request.GET.get('pro', '')),
             ('region', request.REGION.slug),
         )
         response['API-Filter'] = urlencode(filters, doseq=True)
         patch_vary_headers(response, ['API-Filter'])
     return response
Пример #14
0
 def process_response(self, request, response):
     if getattr(request, "API", False) and response.status_code < 500:
         devices = []
         for device in ("GAIA", "MOBILE", "TABLET"):
             if getattr(request, device, False):
                 devices.append(device.lower())
         filters = (
             ("carrier", get_carrier() or ""),
             ("device", devices),
             ("lang", request.LANG),
             ("pro", request.GET.get("pro", "")),
             ("region", request.REGION.slug),
         )
         response["API-Filter"] = urlencode(filters, doseq=True)
         patch_vary_headers(response, ["API-Filter"])
     return response
Пример #15
0
 def process_response(self, request, response):
     if (request.method == 'POST' and
             request.POST.get('_hijacked', False) and
             response.status_code in (301, 302)):
         view_url = location = response['Location']
         if get_carrier():
             # Strip carrier from URL.
             view_url = '/' + '/'.join(location.split('/')[2:])
         r = copy.copy(request)
         r.method = 'GET'
         # We want only the fragment response.
         r.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
         # Pass back the URI so we can pushState it.
         r.FRAGMENT_URI = location
         view = resolve(view_url)
         response = view.func(r, *view.args, **view.kwargs)
     return response
Пример #16
0
    def process_response(self, request, response):
        if (request.method == 'POST' and
                request.POST.get('_hijacked', False) and
                response.status_code in (301, 302)):
            view_url = location = response['Location']
            frag_bust = response.get('x-frag-bust', None)

            # TODO: We should remove the need for this.
            if get_carrier():
                # Strip carrier from URL.
                view_url = '/' + '/'.join(location.split('/')[2:])

            req = copy.copy(request)
            req.method = 'GET'
            req.path = view_url
            # We want only the fragment response.
            req.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
            # Pass back the URI so we can pushState it.
            req.FRAGMENT_URI = location

            view = resolve(urllib.unquote(view_url).decode('utf-8'))
            response = view.func(req, *view.args, **view.kwargs)

            response['X-URI'] = location
            # If we have a fragment cache bust flag on the first request,
            # perpetrate it on the new request.
            if frag_bust:
                # If there's a fragment bust flag in the new request, merge it
                # with the flag from the old request in the second grossest
                # possible way.
                if 'x-frag-bust' in response:
                    frag_bust = json.dumps(
                        json.loads(frag_bust) +
                        json.loads(response['x-frag-bust']))

                response['x-frag-bust'] = frag_bust

        return response
Пример #17
0
def manifest(request):
    ctx = RequestContext(request)
    use_appcache = 'skip_appcache' not in request.GET
    data = {
        'name': getattr(settings, 'WEBAPP_MANIFEST_NAME',
                        'Firefox Marketplace'),
        'description': 'The Firefox Marketplace',
        'developer': {
            'name': 'Mozilla',
            'url': 'http://mozilla.org',
        },
        'icons': {
            # Using the default addon image until we get a marketplace logo.
            '128': media(ctx, 'img/mkt/logos/128.png'),
            '64': media(ctx, 'img/mkt/logos/64.png'),
            '32': media(ctx, 'img/mkt/logos/32.png'),
        },
        # TODO: when we have specific locales, add them in here.
        'locales': {},
        'default_locale': 'en-US'
    }
    if use_appcache:
        data['appcache_path'] = reverse('django_appcache.manifest')
    if settings.CARRIER_URLS:
        data['launch_path'] = '/%s/' % (get_carrier() or settings.CARRIER_URLS[0])

    manifest_content = json.dumps(data)
    manifest_etag = hashlib.md5(manifest_content).hexdigest()

    @etag(lambda r: manifest_etag)
    def _inner_view(request):
        response = HttpResponse(manifest_content,
                                mimetype='application/x-web-app-manifest+json')
        return response

    return _inner_view(request)
Пример #18
0
 def test_set_carrier_none(self):
     request = self.request('/?carrier=')
     request.COOKIES = {'carrier': 'telefonica'}
     request = self.get('/?carrier=', request)
     eq_(get_carrier(), None)
     assert request.set_cookie.called
Пример #19
0
 def test_set_carrier(self):
     request = self.get('/?carrier=telefonica')
     eq_(get_carrier(), 'telefonica')
     assert request.set_cookie.called
Пример #20
0
    def featured(self,
                 cat=None,
                 region=None,
                 limit=9,
                 mobile=False,
                 gaia=False,
                 tablet=False,
                 profile=None):
        """
        Filters the QuerySet, removing FeaturedApp instances that should
        not be featured based on the passed criteria.

        If a region is defined and there are fewer than `limit` items
        remaining in the resultant queryset, the difference is populated by
        additional apps that are featured worldwide.

        If `profile` (a FeatureProfile object) is provided we filter by the
        profile. If you don't want to filter by these don't pass it. I.e. do
        the device detection for when this happens elsewhere.

        """
        qs = self.active()
        Webapp = get_model('webapps', 'Webapp')

        excluded = Webapp.objects.none()
        if region:
            from mkt.webapps.models import get_excluded_in
            excluded = get_excluded_in(region.id)

        if waffle.switch_is_active('disabled-payments') or not gaia:
            qs = qs.filter(app__premium_type__in=amo.ADDON_FREES)

        qs = qs.for_category(cat)

        carrier = get_carrier()
        if carrier:
            qs = qs.for_carrier(carrier)

        if gaia:
            qs = qs.gaia()
        elif mobile:
            qs = qs.mobile()

        if tablet:
            qs = qs.tablet()

        if profile and waffle.switch_is_active('buchets'):
            # Exclude apps that require any features we don't support.
            qs = qs.filter(**profile.to_kwargs(
                prefix='app___current_version__features__has_'))

        qs_pre_region = qs._clone()

        if region:
            qs = qs.for_region(region).exclude(app__id__in=excluded)

            # Fill the empty spots with Worldwide-featured apps.
            if limit:
                empty_spots = limit - qs.count()
                if empty_spots > 0 and region != mkt.regions.WORLDWIDE:
                    qs |= (qs_pre_region.worldwide().exclude(
                        id__in=[x.id
                                for x in qs]).exclude(app__id__in=excluded))

        if limit:
            qs = qs[:limit]

        return qs
Пример #21
0
 def test_set_carrier(self):
     request = self.get('/?carrier=telefonica')
     eq_(get_carrier(), 'telefonica')
     assert request.set_cookie.called
Пример #22
0
 def test_set_carrier_none(self):
     request = self.request('/?carrier=')
     request.COOKIES = {'carrier': 'telefonica'}
     request = self.get('/?carrier=', request)
     eq_(get_carrier(), None)
     assert request.set_cookie.called
Пример #23
0
    def featured(self, cat=None, region=None, limit=9, mobile=False,
                 gaia=False, tablet=False, profile=None):
        """
        Filters the QuerySet, removing FeaturedApp instances that should
        not be featured based on the passed criteria.

        If a region is defined and there are fewer than `limit` items
        remaining in the resultant queryset, the difference is populated by
        additional apps that are featured worldwide.

        If `profile` (a FeatureProfile object) is provided we filter by the
        profile. If you don't want to filter by these don't pass it. I.e. do
        the device detection for when this happens elsewhere.

        """
        qs = self.active()
        Webapp = get_model('webapps', 'Webapp')

        excluded = Webapp.objects.none()
        if region:
            from mkt.webapps.models import get_excluded_in
            excluded = get_excluded_in(region.id)

        if waffle.switch_is_active('disabled-payments') or not gaia:
            qs = qs.filter(app__premium_type__in=amo.ADDON_FREES)

        qs = qs.for_category(cat)

        carrier = get_carrier()
        if carrier:
            qs = qs.for_carrier(carrier)

        if gaia:
            qs = qs.gaia()
        elif mobile:
            qs = qs.mobile()

        if tablet:
            qs = qs.tablet()

        if profile and waffle.switch_is_active('buchets'):
            # Exclude apps that require any features we don't support.
            qs = qs.filter(**profile.to_kwargs(
                prefix='app___current_version__features__has_'))

        qs_pre_region = qs._clone()

        if region:
            qs = qs.for_region(region).exclude(app__id__in=excluded)

            # Fill the empty spots with Worldwide-featured apps.
            if limit:
                empty_spots = limit - qs.count()
                if empty_spots > 0 and region != mkt.regions.WORLDWIDE:
                    qs |= (qs_pre_region.worldwide()
                           .exclude(id__in=[x.id for x in qs])
                           .exclude(app__id__in=excluded))

        if limit:
            qs = qs[:limit]

        return qs