本文整理汇总了Python中addons.models.Addon.featured_random方法的典型用法代码示例。如果您正苦于以下问题:Python Addon.featured_random方法的具体用法?Python Addon.featured_random怎么用?Python Addon.featured_random使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类addons.models.Addon
的用法示例。
在下文中一共展示了Addon.featured_random方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: personas
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import featured_random [as 别名]
def personas(request, category=None, template=None):
categories, filter, base, category = personas_listing(request, category)
# Pass the count from base instead of letting it come from
# filter.qs.count() since that would join against personas.
count = category.count if category else base.count()
if ('sort' not in request.GET and ((request.MOBILE and not category) or
(not request.MOBILE and count > 4))):
template += 'category_landing.html'
else:
template += 'grid.html'
addons = amo.utils.paginate(request, filter.qs, 30, count=count)
if category:
ids = AddonCategory.creatured_random(category, request.LANG)
featured = manual_order(base, ids, pk_name="addons.id")
else:
ids = Addon.featured_random(request.APP, request.LANG)
featured = manual_order(base, ids, pk_name="addons.id")
ctx = {'categories': categories, 'category': category, 'addons': addons,
'filter': filter, 'sorting': filter.field, 'sort_opts': filter.opts,
'featured': featured, 'search_cat': 'personas',
'is_homepage': category is None and 'sort' not in request.GET}
return jingo.render(request, template, ctx)
示例2: process_request
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import featured_random [as 别名]
def process_request(self, list_type='recommended', addon_type='ALL',
limit=10, platform='ALL', version=None):
"""
Find a list of new or featured add-ons. Filtering is done in Python
for cache-friendliness and to avoid heavy queries.
"""
limit = min(MAX_LIMIT, int(limit))
APP, platform = self.request.APP, platform.lower()
qs = Addon.objects.listed(APP)
shuffle = True
if list_type in ('by_adu', 'featured'):
qs = qs.exclude(type=amo.ADDON_PERSONA)
if list_type == 'newest':
new = date.today() - timedelta(days=NEW_DAYS)
addons = (qs.filter(created__gte=new)
.order_by('-created'))[:limit + BUFFER]
elif list_type == 'by_adu':
addons = qs.order_by('-average_daily_users')[:limit + BUFFER]
shuffle = False # By_adu is an ordered list.
elif list_type == 'hotness':
# Filter to type=1 so we hit visible_idx. Only extensions have a
# hotness index right now so this is not incorrect.
addons = (qs.filter(type=amo.ADDON_EXTENSION)
.order_by('-hotness'))[:limit + BUFFER]
shuffle = False
else:
ids = Addon.featured_random(APP, self.request.LANG)
addons = manual_order(qs, ids[:limit + BUFFER], 'addons.id')
shuffle = False
args = (addon_type, limit, APP, platform, version, shuffle)
f = lambda: self._process(addons, *args)
return cached_with(addons, f, map(encoding.smart_str, args))
示例3: personas
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import featured_random [as 别名]
def personas(request, category=None, template=None):
categories, filter, base, category = personas_listing(request, category)
# Pass the count from base instead of letting it come from
# filter.qs.count() since that would join against personas.
count = category.count if category else base.count()
if "sort" not in request.GET and ((request.MOBILE and not category) or (not request.MOBILE and count > 4)):
template += "category_landing.html"
else:
template += "grid.html"
addons = amo.utils.paginate(request, filter.qs, 30, count=count)
if category:
ids = AddonCategory.creatured_random(category, request.LANG)
featured = manual_order(base, ids, pk_name="addons.id")
else:
ids = Addon.featured_random(request.APP, request.LANG)
featured = manual_order(base, ids, pk_name="addons.id")
ctx = {
"categories": categories,
"category": category,
"addons": addons,
"filter": filter,
"sorting": filter.field,
"sort_opts": filter.opts,
"featured": featured,
"search_cat": "personas",
"is_homepage": category is None and "sort" not in request.GET,
}
return jingo.render(request, template, ctx)
示例4: personas
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import featured_random [as 别名]
def personas(request, category=None):
categories, filter, base, category = personas_listing(request, category)
# Pass the count from base instead of letting it come from
# filter.qs.count() since that would join against personas.
count = category.count if category else base.count()
if 'sort' in request.GET or count < 5:
template = 'grid.html'
else:
template = 'category_landing.html'
addons = amo.utils.paginate(request, filter.qs, 30, count=count)
if category:
ids = AddonCategory.creatured_random(category, request.LANG)
featured = manual_order(base, ids, pk_name="addons.id")
else:
ids = Addon.featured_random(request.APP, request.LANG)
featured = manual_order(base, ids, pk_name="addons.id")
is_homepage = category is None and 'sort' not in request.GET
return jingo.render(request, 'browse/personas/' + template,
{'categories': categories, 'category': category,
'filter': filter, 'addons': addons,
'featured': featured, 'is_homepage': is_homepage,
'search_cat': 'personas'})
示例5: test_featured_duplicated
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import featured_random [as 别名]
def test_featured_duplicated(self):
another = Addon.objects.get(id=1003)
self.change_addon(another, 'en-US')
another.feature_set.create(application_id=amo.FIREFOX.id,
locale=None,
start=datetime.today(),
end=datetime.today())
eq_(Addon.featured_random(amo.FIREFOX, 'en-US').count(1003), 1)
示例6: test_featured_ids
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import featured_random [as 别名]
def test_featured_ids(self):
another = Addon.objects.get(id=1003)
self.change_addon(another, 'en-US')
items = Addon.featured_random(amo.FIREFOX, 'en-US')
# The order should be random within those boundaries.
eq_([1003, 3481], sorted(items[0:2]))
eq_([1001, 2464, 7661, 15679], sorted(items[2:]))
示例7: test_homepage_filter
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import featured_random [as 别名]
def test_homepage_filter(self):
# Ensure that the base homepage filter is applied.
res = self.client.get(reverse('home'))
listed = [p.pk for p in Addon.objects
.listed(amo.FIREFOX)
.exclude(type=amo.ADDON_PERSONA)]
featured = Addon.featured_random(amo.FIREFOX, 'en-US')
actual = [p.pk for p in res.context['filter'].filter('featured')]
eq_(sorted(actual), sorted(set(listed) & set(featured)))
示例8: personas
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import featured_random [as 别名]
def personas(request, category=None, template=None):
listing = personas_listing(request, category)
# I guess this was a Complete Theme after all.
if isinstance(listing, (HttpResponsePermanentRedirect, HttpResponseRedirect)):
return listing
categories, filter_, base, cat = listing
if filter_.field == "up-and-coming":
# Almost hardcoding the number of element because performing
# `filter_.qs.count()` is a performance killer. We're still
# verifying the `base.count()` for the template switch below.
base_count = base.count()
count = (
base_count if base_count < MIN_COUNT_FOR_LANDING else PAGINATE_PERSONAS_BY * settings.PERSONA_DEFAULT_PAGES
)
else:
# Pass the count from base instead of letting it come from
# filter_.qs.count() since that would join against personas.
count = cat.count if cat else base.count()
addons = amo.utils.paginate(request, filter_.qs, PAGINATE_PERSONAS_BY, count=count)
if "sort" not in request.GET and (
(request.MOBILE and not cat) or (not request.MOBILE and count > MIN_COUNT_FOR_LANDING)
):
template += "category_landing.html"
else:
template += "grid.html"
if cat:
ids = AddonCategory.creatured_random(cat, request.LANG)
featured = manual_order(base, ids, pk_name="addons.id")
else:
ids = Addon.featured_random(request.APP, request.LANG)
featured = manual_order(base, ids, pk_name="addons.id")
ctx = {
"categories": categories,
"category": cat,
"addons": addons,
"filter": filter_,
"sorting": filter_.field,
"sort_opts": filter_.opts,
"featured": featured,
"search_cat": "themes",
"is_homepage": cat is None and "sort" not in request.GET,
}
return render(request, template, ctx)
示例9: get
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import featured_random [as 别名]
def get(self, request, api_version, list_type='recommended',
addon_type='ALL', limit=10, platform='ALL', version=None,
compat_mode='strict', format=None):
"""
Find a list of new or featured add-ons. Filtering is done in Python
for cache-friendliness and to avoid heavy queries.
"""
limit = min(MAX_LIMIT, int(limit))
APP, platform = self.request.APP, platform.lower()
qs = Addon.objects.listed(APP).exclude(type=amo.ADDON_WEBAPP)
shuffle = True
if list_type in ('by_adu', 'featured'):
qs = qs.exclude(type=amo.ADDON_PERSONA)
if list_type == 'newest':
new = date.today() - timedelta(days=NEW_DAYS)
addons = (qs.filter(created__gte=new)
.order_by('-created'))[:limit + BUFFER]
elif list_type == 'by_adu':
addons = qs.order_by('-average_daily_users')[:limit + BUFFER]
shuffle = False # By_adu is an ordered list.
elif list_type == 'hotness':
# Filter to type=1 so we hit visible_idx. Only extensions have a
# hotness index right now so this is not incorrect.
addons = (qs.filter(type=amo.ADDON_EXTENSION)
.order_by('-hotness'))[:limit + BUFFER]
shuffle = False
else:
ids = Addon.featured_random(APP, self.request.LANG)
addons = manual_order(qs, ids[:limit + BUFFER], 'addons.id')
shuffle = False
args = (addon_type, limit, APP, platform, version, compat_mode,
shuffle)
response = self.create_response(addon_filter(addons, *args))
# Storing addons within the response to be able to use it later
# in `self.finalize_response()` as a cache key.
response.addons = addons
return response
示例10: featured
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import featured_random [as 别名]
def featured(request, category=None, template=None):
ids = Addon.featured_random(request.APP, request.LANG)
addons = manual_order(Addon.objects.exclude(type=amo.ADDON_PERSONA), ids)
return jingo.render(request, template, {'addons': addons})