本文整理汇总了Python中addons.models.Addon.new_featured_random方法的典型用法代码示例。如果您正苦于以下问题:Python Addon.new_featured_random方法的具体用法?Python Addon.new_featured_random怎么用?Python Addon.new_featured_random使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类addons.models.Addon
的用法示例。
在下文中一共展示了Addon.new_featured_random方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_request
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import new_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:
if settings.NEW_FEATURES:
ids = Addon.new_featured_random(APP, self.request.LANG)
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))