Ticket #4956: reverse_pagination.patch

File reverse_pagination.patch, 1.3 KB (added by Amit Upadhyay <upadhyay@…>, 17 years ago)

reverse paginator implementation.

  • views/generic/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
     
    4545    if paginate_by:
    4646        paginator = ObjectPaginator(queryset, paginate_by)
    4747        if not page:
    48             page = request.GET.get('page', 1)
     48            if reverse_pagination:
     49                page = request.GET.get('page', paginator.pages)
     50            else:
     51                page = request.GET.get('page', 1)
    4952        try:
    5053            page = int(page)
    5154            object_list = paginator.get_page(page - 1)
     
    5457                object_list = []
    5558            else:
    5659                raise Http404
     60        if reverse_pagination:
     61            object_list = list(reversed(list(object_list)))
    5762        c = RequestContext(request, {
    5863            '%s_list' % template_object_name: object_list,
    5964            'is_paginated': paginator.pages > 1,
Back to Top