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


Python utils.clean_sort_param函数代码示例

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


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

示例1: _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('-addon__priority_review', 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:petercpg,项目名称:zamboni,代码行数:32,代码来源:views.py

示例2: sort_link

def sort_link(context, pretty_name, sort_field):
    """Get table header sort links.

    pretty_name -- name displayed on table header
    sort_field -- name of get parameter, referenced to in views
    """
    request = context["request"]
    sort, order = clean_sort_param(request)

    # Copy search/filter GET parameters.
    get_params = [
        (k, v) for k, v in urlparse.parse_qsl(smart_str(request.META["QUERY_STRING"])) if k not in ("sort", "order")
    ]

    return create_sort_link(pretty_name, sort_field, get_params, sort, order)
开发者ID:petercpg,项目名称:zamboni,代码行数:15,代码来源:helpers.py

示例3: _do_sort

def _do_sort(request, qs):
    """Column sorting logic based on request GET parameters."""
    sort, order = clean_sort_param(request)
    if order == 'asc':
        order_by = sort
    else:
        order_by = '-%s' % sort

    if sort == 'name':
        return order_by_translation(qs, order_by)
    elif sort == 'num_abuse_reports':
        return (qs.annotate(num_abuse_reports=Count('abuse_reports'))
                .order_by(order_by))
    else:
        return qs.order_by(order_by)
开发者ID:dimonov,项目名称:zamboni,代码行数:15,代码来源:views.py

示例4: _do_sort_webapp

def _do_sort_webapp(request, qs, date_sort):
    """
    Column sorting logic based on request GET parameters.
    """
    sort_type, order = clean_sort_param(request, date_sort=date_sort)
    order_by = ('-' if order == 'desc' else '') + sort_type

    # Sort.
    if sort_type == 'name':
        # Sorting by name translation.
        return order_by_translation(qs, order_by)

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

    else:
        return qs.order_by('-priority_review', order_by)
开发者ID:petercpg,项目名称:zamboni,代码行数:18,代码来源:views.py

示例5: _do_sort

def _do_sort(request, qs, date_field="created"):
    """Column sorting logic based on request GET parameters."""
    sort, order = clean_sort_param(request, date_field=date_field)

    if qs.model is not Webapp and sort != date_field:
        # For when `Webapp` isn't the base model of the queryset.
        sort = "addon__" + sort

    if order == "asc":
        order_by = sort
    else:
        order_by = "-%s" % sort

    if sort == "name":
        return order_by_translation(qs, order_by)
    elif sort == "num_abuse_reports":
        return qs.annotate(num_abuse_reports=Count("abuse_reports")).order_by(order_by)
    else:
        return qs.order_by(order_by)
开发者ID:steekid,项目名称:zamboni,代码行数:19,代码来源:views.py

示例6: _do_sort

def _do_sort(request, qs, date_field='created'):
    """Column sorting logic based on request GET parameters."""
    sort, order = clean_sort_param(request, date_field=date_field)

    if qs.model is not Webapp and sort != date_field:
        # For when `Webapp` isn't the base model of the queryset.
        sort = 'addon__' + sort

    if order == 'asc':
        order_by = sort
    else:
        order_by = '-%s' % sort

    if sort == 'name':
        return order_by_translation(qs, order_by)
    elif sort == 'num_abuse_reports':
        return (qs.annotate(num_abuse_reports=Count('abuse_reports'))
                .order_by(order_by))
    else:
        return qs.order_by(order_by)
开发者ID:wraithan,项目名称:zamboni,代码行数:20,代码来源:views.py

示例7: _do_sort

def _do_sort(request, qs):
    """Column sorting logic based on request GET parameters."""
    sort, order = clean_sort_param(request)

    if qs.model in [EscalationQueue, RereviewQueue] and sort != 'created':
        # For some queues, want to use queue's created field, not the app's
        # created field.
        sort = 'addon__' + sort

    if order == 'asc':
        order_by = sort
    else:
        order_by = '-%s' % sort

    if sort == 'name':
        return order_by_translation(qs, order_by)
    elif sort == 'num_abuse_reports':
        return (qs.annotate(num_abuse_reports=Count('abuse_reports'))
                .order_by(order_by))
    else:
        return qs.order_by(order_by)
开发者ID:bearstech,项目名称:zamboni,代码行数:21,代码来源:views.py


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