Ticket #4956: reverse_paginator.patch

File reverse_paginator.patch, 1.5 KB (added by Amit Upadhyay <upadhyay@…>, 8 years ago)

ignore the previous patch.

  • list_detail.py

     
    77def object_list(request, queryset, paginate_by=None, page=None,
    88        allow_empty=False, template_name=None, template_loader=loader,
    99        extra_context=None, context_processors=None, template_object_name='object',
    10         mimetype=None):
     10        mimetype=None, reverse_pagination=False):
    1111    """
    1212    Generic list of objects.
    1313
     
    4343    if extra_context is None: extra_context = {}
    4444    queryset = queryset._clone()
    4545    if paginate_by:
    46         paginator = ObjectPaginator(queryset, paginate_by)
     46        if reverse_pagination:
     47            paginator = ObjectPaginator(queryset, paginate_by, paginate_by - 1)
     48        else:
     49            paginator = ObjectPaginator(queryset, paginate_by)
    4750        if not page:
    48             page = request.GET.get('page', 1)
     51            if reverse_pagination:
     52                page = request.GET.get('page', paginator.pages)
     53            else:
     54                page = request.GET.get('page', 1)
    4955        try:
    5056            page = int(page)
    5157            object_list = paginator.get_page(page - 1)
     
    5460                object_list = []
    5561            else:
    5662                raise Http404
     63        if reverse_pagination:
     64            object_list = list(reversed(list(object_list)))
    5765        c = RequestContext(request, {
    5866            '%s_list' % template_object_name: object_list,
    5967            'is_paginated': paginator.pages > 1,
Back to Top