Ticket #3169: page_list.diff
File page_list.diff, 2.9 KB (added by , 18 years ago) |
---|
-
django/views/generic/list_detail.py
5 5 from django.core.exceptions import ObjectDoesNotExist 6 6 7 7 def 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): 11 11 """ 12 12 Generic list of objects. 13 13 … … 33 33 number of pages, total 34 34 hits 35 35 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 36 39 """ 37 40 if extra_context is None: extra_context = {} 38 41 queryset = queryset._clone() … … 48 51 object_list = [] 49 52 else: 50 53 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 = [] 51 64 c = RequestContext(request, { 52 65 '%s_list' % template_object_name: object_list, 53 66 'is_paginated': paginator.pages > 1, … … 59 72 'previous': page - 1, 60 73 'pages': paginator.pages, 61 74 'hits' : paginator.hits, 75 'page_list': page_list 62 76 }, context_processors) 63 77 else: 64 78 c = RequestContext(request, { -
docs/generic_views.txt
706 706 the view will raise a 404 instead of displaying an empty page. By 707 707 default, this is ``False``. 708 708 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 709 712 * ``context_processors``: A list of template-context processors to apply to 710 713 the view's template. See the `RequestContext docs`_. 711 714 … … 757 760 * ``hits``: The total number of objects across *all* pages, not just this 758 761 page. 759 762 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 760 767 Notes on pagination 761 768 ~~~~~~~~~~~~~~~~~~~ 762 769