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


Python Addon.search_public方法代码示例

本文整理汇总了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)
开发者ID:jvillalobos,项目名称:olympia,代码行数:50,代码来源:views.py

示例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
开发者ID:jvillalobos,项目名称:olympia,代码行数:20,代码来源:views.py

示例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)
开发者ID:jvillalobos,项目名称:olympia,代码行数:84,代码来源:views.py


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