Ticket #3169: page_list.diff

File page_list.diff, 2.9 KB (added by Grimboy, 18 years ago)
  • django/views/generic/list_detail.py

     
    55from django.core.exceptions import ObjectDoesNotExist
    66
    77def object_list(request, queryset, paginate_by=None, page=None,
    8         allow_empty=False, template_name=None, template_loader=loader,
    9         extra_context=None, context_processors=None, template_object_name='object',
    10         mimetype=None):
     8        allow_empty=False, surrounding_pages=0, template_name=None,
     9        template_loader=loader, extra_context=None, context_processors=None,
     10        template_object_name='object', mimetype=None):
    1111    """
    1212    Generic list of objects.
    1313
     
    3333            number of pages, total
    3434        hits
    3535            number of objects, total
     36        page_list
     37            a list of containing the a list of page numbers surrounding and
     38            including the current page
    3639    """
    3740    if extra_context is None: extra_context = {}
    3841    queryset = queryset._clone()
     
    4851                object_list = []
    4952            else:
    5053                raise Http404
     54        if surrounding_pages:
     55            surround_start = page-surrounding_pages
     56            surround_end = page+surrounding_pages
     57            if surround_start < 1:
     58                surround_start = 1
     59            if surround_end > paginator.pages:
     60                surround_end = paginator.pages
     61            page_list = range(surround_start, surround_end+1)
     62        else:
     63            page_list = []
    5164        c = RequestContext(request, {
    5265            '%s_list' % template_object_name: object_list,
    5366            'is_paginated': paginator.pages > 1,
     
    5972            'previous': page - 1,
    6073            'pages': paginator.pages,
    6174            'hits' : paginator.hits,
     75            'page_list': page_list
    6276        }, context_processors)
    6377    else:
    6478        c = RequestContext(request, {
  • docs/generic_views.txt

     
    706706      the view will raise a 404 instead of displaying an empty page. By
    707707      default, this is ``False``.
    708708
     709    * **New in Django development version** ``surrounding_pages``: The number
     710      of pages on either side of the current page to include in ``page_list``.
     711
    709712    * ``context_processors``: A list of template-context processors to apply to
    710713      the view's template. See the `RequestContext docs`_.
    711714
     
    757760    * ``hits``: The total number of objects across *all* pages, not just this
    758761      page.
    759762
     763    * **New in Django development version** ``page_list``: A 1-based ordered
     764      list of page numbers surrounding and including the current page. Empty if
     765      ``surrounding_pages`` is zero.
     766
    760767Notes on pagination
    761768~~~~~~~~~~~~~~~~~~~
    762769
Back to Top