Пример #1
0
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')
Пример #2
0
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')
Пример #3
0
def _do_sort(request, qs):
    """Returns an order_by string 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)
    else:
        return qs.order_by(order_by)
Пример #4
0
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)
Пример #5
0
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)
Пример #6
0
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, smart_str(v)) for k, v in request.GET.items()
                  if k not in ('sort', 'order')]

    return create_sort_link(pretty_name, sort_field, get_params,
                            sort, order)
Пример #7
0
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)
Пример #8
0
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)
Пример #9
0
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(order_by)
Пример #10
0
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)
Пример #11
0
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)
Пример #12
0
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)
Пример #13
0
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)
Пример #14
0
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)