当前位置: 首页>>代码示例>>Python>>正文


Python Webapp.search方法代码示例

本文整理汇总了Python中mkt.webapps.models.Webapp.search方法的典型用法代码示例。如果您正苦于以下问题:Python Webapp.search方法的具体用法?Python Webapp.search怎么用?Python Webapp.search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mkt.webapps.models.Webapp的用法示例。


在下文中一共展示了Webapp.search方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: app_search

# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import search [as 别名]
def app_search(request, tag_name=None, template=None):
    form = ESSearchForm(request.GET.copy() or {}, type=amo.ADDON_WEBAPP)
    form.is_valid()  # Let the form try to clean data.
    query = form.cleaned_data
    # TODO(apps): We should figure out if we really want tags for apps.
    if tag_name:
        query['tag'] = tag_name

    qs = (Webapp.search()
          .filter(type=amo.ADDON_WEBAPP, status=amo.STATUS_PUBLIC,
                  is_disabled=False)
          .facet(tags={'terms': {'field': 'tag'}},
                 categories={'terms': {'field': 'category', 'size': 200}}))

    filters = ['cat', 'price', 'sort', 'tag']
    mapping = {'downloads': '-weekly_downloads',
               'rating': '-bayesian_rating',
               'created': '-created',
               'name': 'name_sort',
               'hotness': '-hotness',
               'price': 'price'}
    qs = _filter_search(request, qs, query, filters, mapping,
                        types=[amo.ADDON_WEBAPP])

    pager = amo.utils.paginate(request, qs)
    facets = pager.object_list.facets

    sort, extra_sort = split_choices(form.sort_choices, 'price')

    ctx = {
        'is_pjax': request.META.get('HTTP_X_PJAX'),
        'pager': pager,
        'query': query,
        'form': form,
        'sorting': sort_sidebar(request, query, form),
        'sort_opts': sort,
        'extra_sort_opts': extra_sort,
        'sort': query.get('sort'),
        'webapp': True,
    }
    if not ctx['is_pjax']:
        ctx.update({
            'prices': price_sidebar(request, query, facets),
            'categories': category_sidebar(request, query, facets),
            'tags': tag_sidebar(request, query, facets),
        })
    return jingo.render(request, template, ctx)
开发者ID:beenishkhan,项目名称:zamboni,代码行数:49,代码来源:views.py

示例2: _get_query

# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import search [as 别名]
def _get_query(request, form, query):
    return (Webapp.search()
            .query(type=amo.ADDON_WEBAPP, status=amo.STATUS_PUBLIC,
                   is_disabled=False)
            .facet(categories={'terms': {'field': 'category', 'size': 200}}))
开发者ID:ominds,项目名称:zamboni,代码行数:7,代码来源:views.py

示例3: _app_search

# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import search [as 别名]
def _app_search(request, category=None, browse=None):
    form = forms.AppSearchForm(request.GET)
    form.is_valid()  # Let the form try to clean data.
    query = form.cleaned_data

    # Remove `sort=price` if `price=free`.
    if query.get("price") == "free" and query.get("sort") == "price":
        return {"redirect": amo.utils.urlparams(request.get_full_path(), sort=None)}

    qs = (
        Webapp.search()
        .filter(type=amo.ADDON_WEBAPP, status=amo.STATUS_PUBLIC, is_disabled=False)
        .facet(categories={"terms": {"field": "category", "size": 200}})
    )

    filters = ["cat", "price", "device", "sort"]
    sorting = {
        "downloads": "-weekly_downloads",
        "rating": "-bayesian_rating",
        "created": "-created",
        "name": "name_sort",
        "hotness": "-hotness",
        "price": "price",
    }
    qs = _filter_search(qs, query, filters, sorting)

    pager = amo.utils.paginate(request, qs)
    facets = pager.object_list.facets

    if category or browse:
        sort_opts = forms.LISTING_SORT_CHOICES
    else:
        if query.get("price") == "free":
            # Remove 'Sort by Price' option if filtering by free apps.
            sort_opts = forms.FREE_SORT_CHOICES
        else:
            sort_opts = form.fields["sort"].choices

    cats = [f["term"] for f in facets["categories"]]
    categories = Category.objects.filter(type=amo.ADDON_WEBAPP, id__in=cats)

    # If category is not listed as a facet, then remove `cat` and redirect.
    if query.get("cat") and query["cat"] not in categories.values_list("id", flat=True):
        if category:
            return {"redirect": reverse("search.search")}
        else:
            return {"redirect": amo.utils.urlparams(request.get_full_path(), cat=None)}

    ctx = {
        "pager": pager,
        "query": query,
        "form": form,
        "sorting": sort_sidebar(query, form),
        "sort_opts": sort_opts,
        "extra_sort_opts": [],
        "sort": query.get("sort"),
        "price": query.get("price"),
        "categories": category_sidebar(query, categories),
        "prices": price_sidebar(query),
        "devices": device_sidebar(query),
        "active": {},
    }

    applied_filters = []
    for facet in ("prices", "categories", "devices"):
        for idx, f in enumerate(ctx[facet]):
            # Show filters where something besides its first/default choice
            # is selected.
            if idx and f.selected:
                applied_filters.append(f)
                ctx["active"][facet] = f

    # We shouldn't show the "Applied Filters" for category browse/search pages.
    if not category:
        ctx["applied_filters"] = applied_filters

    return ctx
开发者ID:beenishkhan,项目名称:zamboni,代码行数:79,代码来源:views.py

示例4: _app_search

# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import search [as 别名]
def _app_search(request, category=None):
    form = forms.AppSearchForm(request.GET)
    form.is_valid()  # Let the form try to clean data.
    query = form.cleaned_data

    # Remove `sort=price` if `price=free`.
    if query.get('price') == 'free' and query.get('sort') == 'price':
        return {'redirect': amo.utils.urlparams(request.get_full_path(),
                                                sort=None)}

    qs = (Webapp.search()
          .filter(type=amo.ADDON_WEBAPP, status=amo.STATUS_PUBLIC,
                  is_disabled=False)
          .facet(categories={'terms': {'field': 'category', 'size': 200}}))

    filters = ['cat', 'price', 'device', 'sort']
    sorting = {'downloads': '-weekly_downloads',
               'rating': '-bayesian_rating',
               'created': '-created',
               'name': 'name_sort',
               'hotness': '-hotness',
               'price': 'price'}
    qs = _filter_search(qs, query, filters, sorting)

    pager = amo.utils.paginate(request, qs)
    facets = pager.object_list.facets

    if category:
        sort_opts = forms.LISTING_SORT_CHOICES
    else:
        if query.get('price') == 'free':
            # Remove 'Sort by Price' option if filtering by free apps.
            sort_opts = forms.FREE_SORT_CHOICES
        else:
            sort_opts = form.fields['sort'].choices

    cats = [f['term'] for f in facets['categories']]
    categories = Category.objects.filter(type=amo.ADDON_WEBAPP, id__in=cats)

    # If category is not listed as a facet, then remove `cat` and redirect.
    if (query.get('cat') and
        query['cat'] not in categories.values_list('id', flat=True)):
        if category:
            return {'redirect': reverse('search.search')}
        else:
            return {'redirect': amo.utils.urlparams(request.get_full_path(),
                                                    cat=None)}

    ctx = {
        'pager': pager,
        'query': query,
        'form': form,
        'sorting': sort_sidebar(query, form),
        'sort_opts': sort_opts,
        'extra_sort_opts': [],
        'sort': query.get('sort'),
        'categories': category_sidebar(query, categories),
        'prices': price_sidebar(query),
        'devices': device_sidebar(query),
        'active': {},
    }

    applied_filters = []
    for facet in ['prices', 'categories', 'devices']:
        for idx, f in enumerate(ctx[facet]):
            # Show filters where something besides its first/default choice
            # is selected.
            if idx and f.selected:
                applied_filters.append(f)
                ctx['active'][facet] = f

    # We shouldn't show the "Applied Filters" for category browse/search pages.
    if not category:
        ctx['applied_filters'] = applied_filters

    return ctx
开发者ID:pjajara,项目名称:zamboni,代码行数:78,代码来源:views.py


注:本文中的mkt.webapps.models.Webapp.search方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。