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


Python query.order_by_translation函数代码示例

本文整理汇总了Python中translations.query.order_by_translation函数的典型用法代码示例。如果您正苦于以下问题:Python order_by_translation函数的具体用法?Python order_by_translation怎么用?Python order_by_translation使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_sorting_mixed

    def test_sorting_mixed(self):
        translation.activate('de')
        q = TranslatedModel.objects.all()
        expected = [1, 4, 3]

        eq_(ids(order_by_translation(q, 'name')), expected)
        eq_(ids(order_by_translation(q, '-name')), list(reversed(expected)))
开发者ID:almosteverywhere,项目名称:zamboni,代码行数:7,代码来源:test_models.py

示例2: test_sorting_by_field

    def test_sorting_by_field(self):
        field = TranslatedModel._meta.get_field('default_locale')
        TranslatedModel.get_fallback = classmethod(lambda cls: field)

        translation.activate('de')
        q = TranslatedModel.objects.all()
        expected = [3, 1, 4]

        eq_(ids(order_by_translation(q, 'name')), expected)
        eq_(ids(order_by_translation(q, '-name')), list(reversed(expected)))

        del TranslatedModel.get_fallback
开发者ID:almosteverywhere,项目名称:zamboni,代码行数:12,代码来源:test_models.py

示例3: search_tools

def search_tools(request, category=None):
    APP, TYPE = request.APP, amo.ADDON_SEARCH
    qs = Category.objects.filter(application=APP.id, type=TYPE)
    categories = order_by_translation(qs, 'name')

    # Feature page should list both extensions and search Add-ons
    # but other pages should only list search Add-ons

    types = [TYPE]
    default = 'featured'
    if request.GET.get('sort', default) == 'featured':
        types.append(amo.ADDON_EXTENSION)

    addons, filter, unreviewed = addon_listing(
        request, types, SearchToolsFilter, default)

    if category is not None:
        category = get_object_or_404(qs, slug=category)
        addons = addons.filter(categories__id=category.id)

    addons = amo.utils.paginate(request, addons)

    base = (Addon.objects.listed(request.APP, amo.STATUS_PUBLIC)
                         .filter(type=amo.ADDON_EXTENSION))
    search_extensions = SearchExtensionsFilter(
                            request, base, 'sort', 'popular')

    return jingo.render(request, 'browse/search_tools.html',
                        {'categories': categories, 'category': category,
                         'addons': addons, 'filter': filter,
                         'search_extensions_filter': search_extensions,
                         'unreviewed': unreviewed})
开发者ID:ozten,项目名称:zamboni,代码行数:32,代码来源:views.py

示例4: themes

def themes(request, category=None):
    q = Category.objects.filter(application=request.APP.id,
                                type=amo.ADDON_THEME)
    categories = order_by_translation(q, 'name')

    addons, filter, unreviewed = _listing(request, amo.ADDON_THEME)

    if category is not None:
        try:
            category = dict((c.slug, c) for c in categories)[category]
        except KeyError:
            raise http.Http404()
        addons = addons.filter(categories__id=category.id)

    count = addons.with_index(addons='type_status_inactive_idx').count()
    themes = amo.utils.paginate(request, addons, count=count)

    # Pre-selected category for search form
    search_cat = '%s,0' % amo.ADDON_THEME

    return jingo.render(request, 'browse/themes.html',
                        {'categories': categories,
                         'themes': themes, 'category': category,
                         'sorting': filter.field,
                         'sort_opts': filter.opts,
                         'unreviewed': unreviewed,
                         'search_cat': search_cat})
开发者ID:jaliste,项目名称:zamboni,代码行数:27,代码来源:views.py

示例5: themes

def themes(request, category=None):
    q = Category.objects.filter(application=request.APP.id,
                                type=amo.ADDON_THEME)
    categories = order_by_translation(q, 'name')

    addons, filter, unreviewed = _listing(request, amo.ADDON_THEME)
    total_count = addons.count()

    if category is None:
        selected = _Category(_('All'), total_count, '')
    else:
        selected = dict((c.slug, c) for c in categories)[category]
        addons = addons.filter(categories__slug=category)

    themes = amo.utils.paginate(request, addons)

    # Pre-selected category for search form
    search_cat = '%s,0' % amo.ADDON_THEME

    return jingo.render(request, 'browse/themes.html',
                        {'categories': categories, 'total_count': total_count,
                         'themes': themes, 'selected': selected,
                         'sorting': filter.sorting,
                         'sort_opts': filter.opts,
                         'unreviewed': unreviewed,
                         'search_cat': search_cat})
开发者ID:landas,项目名称:zamboni,代码行数:26,代码来源:views.py

示例6: personas

def personas(request, category=None):
    TYPE = amo.ADDON_PERSONA
    q = Category.objects.filter(application=request.APP.id,
                                type=TYPE)
    categories = order_by_translation(q, 'name')

    base = Addon.objects.valid().filter(type=TYPE)
    featured = base & Addon.objects.featured(request.APP)
    is_homepage = category is None and 'sort' not in request.GET

    if category is not None:
        category = get_object_or_404(q, slug=category)
        base = base.filter(categories__id=category.id)

    filter = PersonasFilter(request, base, key='sort', default='up-and-coming')

    if 'sort' in request.GET:
        template = 'grid.html'
    else:
        template = 'category_landing.html'

    # Pass the count from base instead of letting it come from
    # filter.qs.count() since that would join against personas.
    addons = amo.utils.paginate(request, filter.qs, 30, count=base.count())

    search_cat = '%s,%s' % (TYPE, category.id if category else 0)

    return jingo.render(request, 'browse/personas/' + template,
                        {'categories': categories, 'category': category,
                         'filter': filter, 'addons': addons,
                         'featured': featured, 'is_homepage': is_homepage,
                         'search_cat': search_cat})
开发者ID:landas,项目名称:zamboni,代码行数:32,代码来源:views.py

示例7: _personas

def _personas(request):
    "Handle the request for persona searches."
    form = SecondarySearchForm(request.GET)
    form.is_valid()

    query = form.cleaned_data.get('q', '')

    search_opts = {}
    search_opts['limit'] = form.cleaned_data.get('pp', DEFAULT_NUM_RESULTS)
    page = form.cleaned_data.get('page') or 1
    search_opts['offset'] = (page - 1) * search_opts['limit']

    client = PersonasClient()

    q = Category.objects.filter(application=request.APP.id,
                                type=amo.ADDON_PERSONA)
    categories = order_by_translation(q, 'name')

    try:
        results = client.query(query, **search_opts)
    except SearchError:
        return jingo.render(request, 'search/down.html', {}, status=503)

    pager = amo.utils.paginate(request, results, search_opts['limit'])

    c = {
            'pager': pager,
            'form': form,
            'categories': categories,
        }

    return jingo.render(request, 'search/personas.html', c)
开发者ID:jaliste,项目名称:zamboni,代码行数:32,代码来源:views.py

示例8: filter

 def filter(self, field):
     if field == "added":
         return self.base_queryset.order_by("collectionaddon__created")
     elif field == "name":
         return order_by_translation(self.base_queryset, "name")
     elif field == "popular":
         return self.base_queryset.order_by("-weekly_downloads").with_index(addons="downloads_type_idx")
开发者ID:rhelmer,项目名称:zamboni,代码行数:7,代码来源:views.py

示例9: my_addons

 def my_addons(self, n=8, with_unlisted=False):
     """Returns n addons"""
     addons = self.addons
     if with_unlisted:
         addons = self.addons.model.with_unlisted.filter(authors=self)
     qs = order_by_translation(addons, 'name')
     return qs[:n]
开发者ID:ddurst,项目名称:olympia,代码行数:7,代码来源:models.py

示例10: personas_listing

def personas_listing(request, category_slug=None):
    # Common pieces using by browse and search.
    TYPE = amo.ADDON_PERSONA
    q = Category.objects.filter(type=TYPE)
    categories = order_by_translation(q, 'name')

    frozen = list(FrozenAddon.objects.values_list('addon', flat=True))

    base = (Addon.objects.public().filter(type=TYPE)
                 .exclude(id__in=frozen)
                 .extra(select={'_app': request.APP.id}))

    cat = None
    if category_slug is not None:
        try:
            cat = Category.objects.filter(slug=category_slug, type=TYPE)[0]
        except IndexError:
            # Maybe it's a Complete Theme?
            try:
                cat = Category.objects.filter(slug=category_slug,
                                              type=amo.ADDON_THEME)[0]
            except IndexError:
                raise Http404
            else:
                # Hey, it was a Complete Theme.
                url = reverse('browse.themes', args=[cat.slug])
                if 'sort' in request.GET:
                    url = amo.utils.urlparams(url, sort=request.GET['sort'])
                return redirect(url, permanent=not settings.DEBUG)

        base = base.filter(categories__id=cat.id)

    filter_ = PersonasFilter(request, base, key='sort',
                             default='up-and-coming')
    return categories, filter_, base, cat
开发者ID:srachit,项目名称:olympia,代码行数:35,代码来源:views.py

示例11: _do_sort_queue_obj

def _do_sort_queue_obj(request, qs, date_sort):
    """
    Column sorting logic based on request GET parameters.
    Deals with objects with joins on the Addon (e.g. RereviewQueue, Version).
    Returns qs of apps.
    """
    sort_type, order = clean_sort_param(request, date_sort=date_sort)
    sort_str = sort_type

    if sort_type not in [date_sort, 'name']:
        sort_str = 'addon__' + sort_type

    # sort_str includes possible joins when ordering.
    # sort_type is the name of the field to sort on without desc/asc markers.
    # order_by is the name of the field to sort on with desc/asc markers.
    order_by = ('-' if order == 'desc' else '') + sort_str

    # Sort.
    if sort_type == 'name':
        # Sorting by name translation through an addon foreign key.
        return order_by_translation(
            Webapp.objects.filter(id__in=qs.values_list('addon', flat=True)),
            order_by)

    elif sort_type == 'num_abuse_reports':
        qs = qs.annotate(num_abuse_reports=Count('abuse_reports'))

    # Convert sorted queue object queryset to sorted app queryset.
    sorted_app_ids = qs.order_by(order_by).values_list('addon', flat=True)
    qs = Webapp.objects.filter(id__in=sorted_app_ids)
    return manual_order(qs, sorted_app_ids, 'addons.id')
开发者ID:lissyx,项目名称:zamboni,代码行数:31,代码来源:views.py

示例12: themes

def themes(request, category=None):
    q = Category.objects.filter(application=request.APP.id, type=amo.ADDON_THEME)
    categories = order_by_translation(q, "name")

    addons, filter, unreviewed = _listing(request, amo.ADDON_THEME)
    total_count = addons.count()

    if category is None:
        selected = _Category(_("All"), total_count, "")
    else:
        selected = dict((c.slug, c) for c in categories)[category]
        addons = addons.filter(categories__slug=category)

    themes = amo.utils.paginate(request, addons)

    # Pre-selected category for search form
    search_cat = "%s,0" % amo.ADDON_THEME

    return jingo.render(
        request,
        "browse/themes.html",
        {
            "categories": categories,
            "total_count": total_count,
            "themes": themes,
            "selected": selected,
            "sorting": filter.sorting,
            "sort_opts": filter.opts,
            "unreviewed": unreviewed,
            "search_cat": search_cat,
        },
    )
开发者ID:rlr,项目名称:zamboni,代码行数:32,代码来源:views.py

示例13: personas

def personas(request, category=None):
    TYPE = amo.ADDON_PERSONA
    q = Category.objects.filter(application=request.APP.id, type=TYPE)
    categories = order_by_translation(q, "name")

    base = Addon.objects.valid().filter(type=TYPE)

    if category is not None:
        category = get_object_or_404(q, slug=category)
        base = base.filter(categories__id=category.id)

    filter = PersonasFilter(request, base, key="sort", default="up-and-coming")

    if "sort" in request.GET:
        template = "grid.html"
    else:
        template = "category_landing.html"

    addons = amo.utils.paginate(request, filter.qs, 30)

    search_cat = "%s,%s" % (TYPE, category.id if category else 0)

    return jingo.render(
        request,
        "browse/personas/" + template,
        {"categories": categories, "category": category, "filter": filter, "addons": addons, "search_cat": search_cat},
    )
开发者ID:rlr,项目名称:zamboni,代码行数:27,代码来源:views.py

示例14: developers

def developers(request, addon, page):
    if 'version' in request.GET:
        qs = addon.versions.filter(files__status__in=amo.VALID_STATUSES)
        version = get_list_or_404(qs, version=request.GET['version'])[0]
    else:
        version = addon.current_version

    if 'src' in request.GET:
        contribution_src = src = request.GET['src']
    else:
        # Download src and contribution_src are be different.
        src = {'developers': 'developers',
               'installed': 'meet-the-developer-post-install',
               'roadblock': 'meetthedeveloper_roadblock'}.get(page, None)
        contribution_src = {'developers': 'meet-developers',
                            'installed': 'post-download',
                            'roadblock': 'roadblock'}.get(page, None)

    if addon.is_persona():
        raise http.Http404()
    author_addons = order_by_translation(addon.authors_other_addons, 'name')
    return jingo.render(request, 'addons/developers.html',
                        {'addon': addon, 'author_addons': author_addons,
                         'page': page, 'src': src,
                         'contribution_src': contribution_src,
                         'version': version})
开发者ID:michaelkirk,项目名称:zamboni,代码行数:26,代码来源:views.py

示例15: themes

def themes(request, category=None):
    APP, THEME = request.APP, amo.ADDON_THEME
    status = [amo.STATUS_PUBLIC]

    experimental = 'on' if request.GET.get('experimental', False) else None
    if experimental:
        status.append(amo.STATUS_SANDBOX)

    q = Category.objects.filter(application=APP.id, type=THEME)
    categories = order_by_translation(q, 'name')

    addons = Addon.objects.listed(APP, *status).filter(type=THEME).distinct()
    total_count = addons.count()

    sorting, sort_opts, addons = AddonSorter(request, addons, 'downloads')

    if category is None:
        selected = _Category(_('All'), total_count, '')
    else:
        selected = dict((c.slug, c) for c in categories)[category]
        addons = addons.filter(categories__slug=category)

    themes = amo.utils.paginate(request, addons)

    return jingo.render(request, 'browse/themes.html',
                        {'categories': categories, 'total_count': total_count,
                         'themes': themes, 'selected': selected,
                         'sorting': sorting, 'sort_opts': sort_opts,
                         'experimental': experimental})
开发者ID:mccammos,项目名称:zamboni,代码行数:29,代码来源:views.py


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