本文整理汇总了Python中addons.models.Addon.search_public方法的典型用法代码示例。如果您正苦于以下问题:Python Addon.search_public方法的具体用法?Python Addon.search_public怎么用?Python Addon.search_public使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类addons.models.Addon
的用法示例。
在下文中一共展示了Addon.search_public方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _personas
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import search_public [as 别名]
def _personas(request):
"""Handle the request for persona searches."""
initial = dict(request.GET.items())
# Ignore these filters since return the same results for Firefox
# as for Thunderbird, etc.
initial.update(appver=None, platform=None)
form = ESSearchForm(initial, type=amo.ADDON_PERSONA)
form.is_valid()
qs = Addon.search_public()
filters = ['sort']
mapping = {
'downloads': '-weekly_downloads',
'users': '-average_daily_users',
'rating': '-bayesian_rating',
'created': '-created',
'name': 'name_sort',
'updated': '-last_updated',
'hotness': '-hotness'
}
results = _filter_search(
request,
qs,
form.cleaned_data,
filters,
sorting=mapping,
types=[amo.ADDON_PERSONA])
form_data = form.cleaned_data.get('q', '')
search_opts = {}
search_opts['limit'] = form.cleaned_data.get('pp', DEFAULT_NUM_PERSONAS)
page = form.cleaned_data.get('page') or 1
search_opts['offset'] = (page - 1) * search_opts['limit']
pager = amo.utils.paginate(request, results, per_page=search_opts['limit'])
categories, filter, base, category = browse.views.personas_listing(request)
c = dict(
pager=pager,
form=form,
categories=categories,
query=form_data,
filter=filter,
search_placeholder='themes')
return render(request, 'search/personas.html', c)
示例2: queryset
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import search_public [as 别名]
def queryset(self):
"""Get items based on ID or search by name."""
results = Addon.objects.none()
q = self.request.GET.get(self.key)
if q:
try:
pk = int(q)
except ValueError:
pk = None
qs = None
if pk:
qs = Addon.objects.reviewed().filter(id=int(q))
elif len(q) > 2:
qs = (Addon.search_public()
.query(or_=name_only_query(q.lower())))
if qs:
results = qs.filter(type__in=self.types)
return results
示例3: search
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import search_public [as 别名]
def search(request, tag_name=None, template=None):
APP = request.APP
types = (amo.ADDON_EXTENSION, amo.ADDON_THEME, amo.ADDON_DICT,
amo.ADDON_SEARCH, amo.ADDON_LPAPP)
category = request.GET.get('cat')
if category == 'collections':
extra_params = {'sort': {'newest': 'created'}}
else:
extra_params = None
fixed = fix_search_query(request.GET, extra_params=extra_params)
if fixed is not request.GET:
return http.HttpResponsePermanentRedirect(urlparams(request.path,
**fixed))
facets = request.GET.copy()
# In order to differentiate between "all versions" and an undefined value,
# we use "any" instead of "" in the frontend.
if 'appver' in facets and facets['appver'] == 'any':
facets['appver'] = ''
form = ESSearchForm(facets or {})
form.is_valid() # Let the form try to clean data.
form_data = form.cleaned_data
if tag_name:
form_data['tag'] = tag_name
if category == 'collections':
return _collections(request)
elif category == 'themes' or form_data.get('atype') == amo.ADDON_PERSONA:
return _personas(request)
sort, extra_sort = split_choices(form.sort_choices, 'created')
if form_data.get('atype') == amo.ADDON_SEARCH:
# Search add-ons should not be searched by ADU, so replace 'Users'
# sort with 'Weekly Downloads'.
sort, extra_sort = list(sort), list(extra_sort)
sort[1] = extra_sort[1]
del extra_sort[1]
qs = (Addon.search_public().filter(app=APP.id)
.facet(tags={'terms': {'field': 'tag'}},
platforms={'terms': {'field': 'platform'}},
appversions={'terms':
{'field': 'appversion.%s.max' % APP.id}},
categories={'terms': {'field': 'category', 'size': 200}}))
filters = ['atype', 'appver', 'cat', 'sort', 'tag', 'platform']
mapping = {'users': '-average_daily_users',
'rating': '-bayesian_rating',
'created': '-created',
'name': 'name_sort',
'downloads': '-weekly_downloads',
'updated': '-last_updated',
'hotness': '-hotness'}
qs = _filter_search(request, qs, form_data, filters, mapping, types=types)
pager = amo.utils.paginate(request, qs)
ctx = {
'is_pjax': request.META.get('HTTP_X_PJAX'),
'pager': pager,
'query': form_data,
'form': form,
'sort_opts': sort,
'extra_sort_opts': extra_sort,
'sorting': sort_sidebar(request, form_data, form),
'sort': form_data.get('sort'),
}
if not ctx['is_pjax']:
facets = pager.object_list.facets
ctx.update({
'tag': tag_name,
'categories': category_sidebar(request, form_data, facets),
'platforms': platform_sidebar(request, form_data, facets),
'versions': version_sidebar(request, form_data, facets),
'tags': tag_sidebar(request, form_data, facets),
})
return render(request, template, ctx)