本文整理汇总了Python中mkt.webapps.models.Webapp.featured方法的典型用法代码示例。如果您正苦于以下问题:Python Webapp.featured方法的具体用法?Python Webapp.featured怎么用?Python Webapp.featured使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mkt.webapps.models.Webapp
的用法示例。
在下文中一共展示了Webapp.featured方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _search
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import featured [as 别名]
def _search(request, category=None):
ctx = {'browse': True}
region = getattr(request, 'REGION', mkt.regions.WORLDWIDE)
if category is not None:
qs = Category.objects.filter(type=amo.ADDON_WEBAPP, weight__gte=0)
ctx['category'] = get_object_or_404(qs, slug=category)
ctx['featured'] = Webapp.featured(cat=ctx['category'], region=region,
mobile=request.MOBILE)
# Do a search filtered by this category and sort by Weekly Downloads.
# TODO: Listen to andy and do not modify `request.GET` but at least
# the traceback is fixed now.
request.GET = request.GET.copy()
request.GET.update({'cat': ctx['category'].id})
if not request.GET.get('sort'):
request.GET['sort'] = 'downloads'
else:
ctx['featured'] = Webapp.featured(region=region, mobile=request.MOBILE)
# Always show three (or zero) featured apps - nothing in between.
ctx['featured'] = ctx['featured'][:0 if len(ctx['featured']) < 3 else 3]
ctx.update(_app_search(request, category=ctx.get('category'), browse=True))
# If category is not listed as a facet, then remove redirect to search.
if ctx.get('redirect'):
return http.HttpResponseRedirect(ctx['redirect'])
return jingo.render(request, 'search/results.html', ctx)
示例2: _landing
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import featured [as 别名]
def _landing(request, category=None):
if category:
category = get_object_or_404(Category.objects.filter(type=amo.ADDON_WEBAPP, weight__gte=0), slug=category)
featured = Webapp.featured(category)
popular = Webapp.popular().filter(category=category.id)
else:
popular = Webapp.popular()
featured = Webapp.featured(None)
return jingo.render(
request, "browse/landing.html", {"category": category, "featured": featured[:6], "popular": popular[:6]}
)
示例3: alter_list_data_to_serialize
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import featured [as 别名]
def alter_list_data_to_serialize(self, request, data):
if waffle.switch_is_active('rocketfuel'):
types = (
('collections', COLLECTIONS_TYPE_BASIC),
('featured', COLLECTIONS_TYPE_FEATURED),
('operator', COLLECTIONS_TYPE_OPERATOR),
)
self.filter_fallbacks = {}
for name, col_type in types:
data[name], fallback = self.collections(request,
collection_type=col_type)
if fallback:
self.filter_fallbacks[name] = fallback
else:
form_data = self.get_search_data(request)
region = getattr(request, 'REGION', mkt.regions.WORLDWIDE)
cat_slug = form_data.get('cat')
if cat_slug:
cat_slug = [cat_slug]
# Filter by device feature profile.
profile = self.get_feature_profile(request)
qs = Webapp.featured(cat=cat_slug, region=region, profile=profile)
bundles = (self.build_bundle(obj=obj, request=request) for obj in
qs)
data['featured'] = [AppResource().full_dehydrate(bundle)
for bundle in bundles]
# Alter the _view_name so that statsd logs seperately from search.
request._view_name = 'featured'
return data
示例4: home
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import featured [as 别名]
def home(request):
"""The home page."""
MOBILE = request.MOBILE and not request.TABLET
region = getattr(request, 'REGION', mkt.regions.WORLDWIDE)
featured = Webapp.featured(region=region, cat=None, mobile=False,
limit=6 if MOBILE else 12)
featured_cnt = len(featured)
# Show featured apps in multiples of three.
if MOBILE:
if featured_cnt >= 9:
featured = featured[:9]
elif featured_cnt >= 6:
featured = featured[:6]
elif featured_cnt >= 3:
featured = featured[:3]
else:
if featured_cnt >= 12:
featured = featured[:12]
elif featured_cnt >= 8:
featured = featured[:8]
elif featured_cnt >= 4:
# Once we allow for the giant featured app we'll require at least
# 5 featured apps on desktop.
featured = featured[:4]
return jingo.render(request, 'home/home.html', {
'featured': featured,
})
示例5: alter_list_data_to_serialize
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import featured [as 别名]
def alter_list_data_to_serialize(self, request, data):
if waffle.switch_is_active("rocketfuel"):
types = (
("collections", COLLECTIONS_TYPE_BASIC),
("featured", COLLECTIONS_TYPE_FEATURED),
("operator", COLLECTIONS_TYPE_OPERATOR),
)
for name, col_type in types:
data[name] = self.collections(request, collection_type=col_type)
else:
form_data = self.get_search_data(request)
region = getattr(request, "REGION", mkt.regions.WORLDWIDE)
cat_slug = form_data.get("cat")
if cat_slug:
cat_slug = [cat_slug]
# Filter by device feature profile.
profile = self.get_feature_profile(request)
qs = Webapp.featured(cat=cat_slug, region=region, profile=profile)
bundles = (self.build_bundle(obj=obj, request=request) for obj in qs)
data["featured"] = [AppResource().full_dehydrate(bundle) for bundle in bundles]
# Alter the _view_name so that statsd logs seperately from search.
request._view_name = "featured"
return data
示例6: obj_get_list
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import featured [as 别名]
def obj_get_list(self, request=None, **kwargs):
form = Featured(request.GET,
region=getattr(request, 'REGION',
regions.WORLDWIDE).slug)
if not form.is_valid():
raise self.form_errors(form)
return Webapp.featured(**form.as_featured())
示例7: _landing
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import featured [as 别名]
def _landing(request, category=None):
region = getattr(request, 'REGION', mkt.regions.WORLDWIDE)
if category:
category = get_object_or_404(
Category.objects.filter(type=amo.ADDON_WEBAPP, weight__gte=0),
slug=category)
featured = Webapp.featured(cat=category, region=region)
popular = _add_mobile_filter(request,
Webapp.popular(cat=category, region=region))
else:
popular = _add_mobile_filter(request, Webapp.popular(region=region))
featured = Webapp.featured(region=region)
return jingo.render(request, 'browse/landing.html', {
'category': category,
'featured': featured[:6],
'popular': popular[:6]
})
示例8: home
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import featured [as 别名]
def home(request):
"""The home page."""
if not getattr(request, 'can_view_consumer', True):
return jingo.render(request, 'home/home_walled.html')
featured = Webapp.featured('home')[:3]
popular = Webapp.popular()[:6]
return jingo.render(request, 'home/home.html', {
'featured': featured,
'popular': popular
})
示例9: home
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import featured [as 别名]
def home(request):
"""The home page."""
if not getattr(request, 'can_view_consumer', True):
return jingo.render(request, 'home/home_walled.html')
region = getattr(request, 'REGION', mkt.regions.WORLDWIDE)
featured = Webapp.featured(region=region, cat=None)[:9]
popular = _add_mobile_filter(request, Webapp.popular(region=region))[:10]
latest = _add_mobile_filter(request, Webapp.latest(region=region))[:10]
return jingo.render(request, 'home/home.html', {
'featured': featured,
})
示例10: __init__
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import featured [as 别名]
def __init__(self, *args, **kw):
self.request = kw.pop("request", None)
self.product = kw.pop("product", None)
super(CategoryForm, self).__init__(*args, **kw)
self.cats_before = list(self.product.categories.values_list("id", flat=True))
self.initial["categories"] = self.cats_before
# If this app is featured, category changes are forbidden.
self.disabled = not acl.action_allowed(self.request, "Addons", "Edit") and Webapp.featured(cat=self.cats_before)
示例11: alter_list_data_to_serialize
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import featured [as 别名]
def alter_list_data_to_serialize(self, request, data):
form_data = self.search_form(request)
region = getattr(request, 'REGION', mkt.regions.WORLDWIDE)
if form_data['cat']:
category = Category.objects.get(pk=form_data['cat'])
else:
category = None
bundles = [self.build_bundle(obj=obj, request=request)
for obj in Webapp.featured(cat=category,
region=region)]
data['featured'] = [self.full_dehydrate(bundle) for bundle in bundles]
return data
示例12: home
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import featured [as 别名]
def home(request):
"""The home page."""
if not getattr(request, 'can_view_consumer', True):
return jingo.render(request, 'home/home_walled.html')
featured = Webapp.featured(cat=None)
popular = Webapp.popular()[:10]
latest = Webapp.latest()[:10]
return jingo.render(request, 'home/home.html', {
'featured': featured,
'popular': popular,
'latest': latest
})
示例13: __init__
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import featured [as 别名]
def __init__(self, *args, **kw):
self.request = kw.pop('request', None)
self.product = kw.pop('product', None)
super(CategoryForm, self).__init__(*args, **kw)
self.cats_before = list(self.product.categories
.values_list('id', flat=True))
self.initial['categories'] = self.cats_before
# If this app is featured, category changes are forbidden.
self.disabled = (
not acl.action_allowed(self.request, 'Addons', 'Edit') and
Webapp.featured(cat=self.cats_before)
)
示例14: test_featured_no_creatured
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import featured [as 别名]
def test_featured_no_creatured(self):
# Three creatured apps for this category for the US region.
creatured = []
for x in xrange(3):
app = amo.tests.app_factory()
self.make_featured(app=app, category=None, region=mkt.regions.US)
creatured.append(app)
creatured_ids = [app.id for app in creatured]
# Check that these apps are featured for this category -
# and only in US region.
for abbr, region in mkt.regions.REGIONS_CHOICES:
self.assertSetEqual(
[a.id for a in Webapp.featured(cat=None, region=region)], creatured_ids if abbr == "us" else []
)
示例15: _landing
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import featured [as 别名]
def _landing(request, category=None):
featured = Webapp.featured('category')
popular = Webapp.popular()
if category:
category = get_object_or_404(
Category.objects.filter(type=amo.ADDON_WEBAPP, weight__gte=0),
slug=category)
featured = featured.filter(category=category)[:6]
popular = popular.filter(category=category.id)
return jingo.render(request, 'browse/landing.html', {
'category': category,
'featured': featured[:6],
'popular': popular[:6]
})