本文整理汇总了Python中mkt.carriers.get_carrier函数的典型用法代码示例。如果您正苦于以下问题:Python get_carrier函数的具体用法?Python get_carrier怎么用?Python get_carrier使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_carrier函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: manifest
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: test_set_carrier_to_none_url
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: process_response
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
示例4: featured
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
示例5: manifest
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)
示例6: manifest
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)
示例7: process_response
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
示例8: process_response
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
示例9: process_response
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
示例10: test_set_carrier_none
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
示例11: test_set_carrier
def test_set_carrier(self):
request = self.get('/?carrier=telefonica')
eq_(get_carrier(), 'telefonica')
assert request.set_cookie.called
示例12: featured
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