本文整理汇总了Python中bandwagon.models.Collection.search方法的典型用法代码示例。如果您正苦于以下问题:Python Collection.search方法的具体用法?Python Collection.search怎么用?Python Collection.search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bandwagon.models.Collection
的用法示例。
在下文中一共展示了Collection.search方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _collections
# 需要导入模块: from bandwagon.models import Collection [as 别名]
# 或者: from bandwagon.models.Collection import search [as 别名]
def _collections(request):
"""Handle the request for collections."""
# Sorting by relevance isn't an option. Instead the default is `weekly`.
initial = dict(sort="weekly")
# Update with GET variables.
initial.update(request.GET.items())
# Ignore appver/platform and set default number of collections per page.
initial.update(appver=None, platform=None, pp=DEFAULT_NUM_COLLECTIONS)
form = SecondarySearchForm(initial)
form.is_valid()
qs = Collection.search().filter(listed=True, app=request.APP.id)
filters = ["sort"]
mapping = {
"weekly": "-weekly_subscribers",
"monthly": "-monthly_subscribers",
"all": "-subscribers",
"rating": "-rating",
"created": "-created",
"name": "name_sort",
"updated": "-modified",
}
results = _filter_search(
request,
qs,
form.cleaned_data,
filters,
sorting=mapping,
sorting_default="-weekly_subscribers",
types=amo.COLLECTION_SEARCH_CHOICES,
)
query = form.cleaned_data.get("q", "")
search_opts = {}
search_opts["limit"] = form.cleaned_data.get("pp", DEFAULT_NUM_COLLECTIONS)
page = form.cleaned_data.get("page") or 1
search_opts["offset"] = (page - 1) * search_opts["limit"]
search_opts["sort"] = form.cleaned_data.get("sort")
pager = amo.utils.paginate(request, results, per_page=search_opts["limit"])
c = dict(
pager=pager,
form=form,
query=query,
opts=search_opts,
filter=bandwagon.views.get_filter(request),
search_placeholder="collections",
)
return jingo.render(request, "search/collections.html", c)
示例2: _collections
# 需要导入模块: from bandwagon.models import Collection [as 别名]
# 或者: from bandwagon.models.Collection import search [as 别名]
def _collections(request):
"""Handle the request for collections."""
# Sorting by relevance isn't an option. Instead the default is `weekly`.
initial = dict(sort='weekly')
# Update with GET variables.
initial.update(request.GET.items())
# Ignore appver/platform and set default number of collections per page.
initial.update(appver=None, platform=None, pp=DEFAULT_NUM_COLLECTIONS)
form = SecondarySearchForm(initial)
form.is_valid()
if waffle.switch_is_active('replace-sphinx'):
qs = Collection.search().filter(listed=True, app=request.APP.id)
filters = ['sort']
mapping = {'weekly': '-weekly_subscribers',
'monthly': '-monthly_subscribers',
'all': '-subscribers',
'rating': '-rating',
'created': '-created',
'name': 'name_sort',
'updated': '-modified'}
results = _filter_search(request, qs, form.cleaned_data, filters,
sorting=mapping,
sorting_default='-weekly_subscribers',
types=amo.COLLECTION_SEARCH_CHOICES)
query = form.cleaned_data.get('q', '')
search_opts = {}
search_opts['limit'] = form.cleaned_data.get('pp', DEFAULT_NUM_COLLECTIONS)
page = form.cleaned_data.get('page') or 1
search_opts['offset'] = (page - 1) * search_opts['limit']
search_opts['sort'] = form.cleaned_data.get('sort')
if not waffle.switch_is_active('replace-sphinx'):
# The new hotness calls this `created`. Sphinx still calls it `newest`.
if search_opts['sort'] == 'created':
search_opts['sort'] = 'newest'
try:
results = CollectionsClient().query(query, **search_opts)
except SearchError:
return jingo.render(request, 'search/down.html', {}, status=503)
pager = amo.utils.paginate(request, results, per_page=search_opts['limit'])
c = dict(pager=pager, form=form, query=query, opts=search_opts,
filter=bandwagon.views.get_filter(request),
search_placeholder='collections')
return jingo.render(request, 'search/collections.html', c)
示例3: _collections
# 需要导入模块: from bandwagon.models import Collection [as 别名]
# 或者: from bandwagon.models.Collection import search [as 别名]
def _collections(request):
"""Handle the request for collections."""
# Sorting by relevance isn't an option. Instead the default is `weekly`.
initial = dict(sort='weekly')
# Update with GET variables.
initial.update(request.GET.items())
# Ignore appver/platform and set default number of collections per page.
initial.update(appver=None, platform=None, pp=DEFAULT_NUM_COLLECTIONS)
form = SecondarySearchForm(initial)
form.is_valid()
qs = Collection.search().filter(listed=True, app=request.APP.id)
filters = ['sort']
mapping = {
'weekly': '-weekly_subscribers',
'monthly': '-monthly_subscribers',
'all': '-subscribers',
'rating': '-rating',
'created': '-created',
'name': 'name_sort',
'updated': '-modified'
}
results = _filter_search(
request,
qs,
form.cleaned_data,
filters,
sorting=mapping,
sorting_default='-weekly_subscribers',
types=amo.COLLECTION_SEARCH_CHOICES)
form_data = form.cleaned_data.get('q', '')
search_opts = {}
search_opts['limit'] = form.cleaned_data.get('pp', DEFAULT_NUM_COLLECTIONS)
page = form.cleaned_data.get('page') or 1
search_opts['offset'] = (page - 1) * search_opts['limit']
search_opts['sort'] = form.cleaned_data.get('sort')
pager = amo.utils.paginate(request, results, per_page=search_opts['limit'])
c = dict(
pager=pager,
form=form,
query=form_data,
opts=search_opts,
filter=bandwagon.views.get_filter(request),
search_placeholder='collections')
return render(request, 'search/collections.html', c)
示例4: es_collections_json
# 需要导入模块: from bandwagon.models import Collection [as 别名]
# 或者: from bandwagon.models.Collection import search [as 别名]
def es_collections_json(request):
app = request.GET.get("app", "")
q = request.GET.get("q", "")
qs = Collection.search()
try:
qs = qs.query(id__startswith=int(q))
except ValueError:
qs = qs.query(name__text=q)
try:
qs = qs.filter(app=int(app))
except ValueError:
pass
data = []
for c in qs[:7]:
data.append({"id": c.id, "name": unicode(c.name), "all_personas": c.all_personas, "url": c.get_url_path()})
return data
示例5: es_collections_json
# 需要导入模块: from bandwagon.models import Collection [as 别名]
# 或者: from bandwagon.models.Collection import search [as 别名]
def es_collections_json(request):
app = request.GET.get('app', '')
q = request.GET.get('q', '')
qs = Collection.search()
try:
qs = qs.query(id__startswith=int(q))
except ValueError:
qs = qs.query(name__text=q)
try:
qs = qs.filter(app=int(app))
except ValueError:
pass
data = []
for c in qs[:7]:
data.append({'id': c.id,
'name': unicode(c.name),
'all_personas': c.all_personas,
'url': c.get_url_path()})
return data