Ticket #4919: lastpage.diff
File lastpage.diff, 3.8 KB (added by , 17 years ago) |
---|
-
django/views/generic/list_detail.py
47 47 if not page: 48 48 page = request.GET.get('page', 1) 49 49 try: 50 page = int(page) 51 object_list = paginator.get_page(page - 1) 52 except (InvalidPage, ValueError): 53 if page == 1 and allow_empty: 50 page_number = int(page) 51 except ValueError: 52 if page == 'last': 53 page_number = paginator.pages 54 else: 55 # Page is not 'last', nor can it be converted to an int 56 raise Http404 57 try: 58 object_list = paginator.get_page(page_number - 1) 59 except InvalidPage: 60 if page_number == 1 and allow_empty: 54 61 object_list = [] 55 62 else: 56 63 raise Http404 … … 58 65 '%s_list' % template_object_name: object_list, 59 66 'is_paginated': paginator.pages > 1, 60 67 'results_per_page': paginate_by, 61 'has_next': paginator.has_next_page(page - 1),62 'has_previous': paginator.has_previous_page(page - 1),63 'page': page ,64 'next': page + 1,65 'previous': page - 1,66 'last_on_page': paginator.last_on_page(page - 1),67 'first_on_page': paginator.first_on_page(page - 1),68 'has_next': paginator.has_next_page(page_number - 1), 69 'has_previous': paginator.has_previous_page(page_number - 1), 70 'page': page_number, 71 'next': page_number + 1, 72 'previous': page_number - 1, 73 'last_on_page': paginator.last_on_page(page_number - 1), 74 'first_on_page': paginator.first_on_page(page_number - 1), 68 75 'pages': paginator.pages, 69 76 'hits' : paginator.hits, 70 77 }, context_processors) -
docs/generic_views.txt
688 688 * ``paginate_by``: An integer specifying how many objects should be 689 689 displayed per page. If this is given, the view will paginate objects with 690 690 ``paginate_by`` objects per page. The view will expect either a ``page`` 691 query string parameter (via ``GET``) containing a 1-based page 692 number, or a ``page`` variable specified in the URLconf. See 693 "Notes on pagination" below. 691 query string parameter (via ``GET``) or a ``page`` variable specified in 692 the URLconf. See "Notes on pagination" below. 694 693 695 694 * ``template_name``: The full name of a template to use in rendering the 696 695 page. This lets you override the default template name (see below). … … 777 776 (r'^objects/page(?P<page>[0-9]+)/$', 'object_list', dict(info_dict)) 778 777 779 778 * Pass the page number via the ``page`` query-string parameter. For 780 example, a URL would look like this: 779 example, a URL would look like this:: 781 780 782 781 /objects/?page=3 783 782 784 783 In both cases, ``page`` is 1-based, not 0-based, so the first page would be 785 represented as page ``1``. 784 represented as page ``1``. As a special case, you are also permitted to use 785 ``last`` as a value for ``page``, like so:: 786 786 787 /objects/?page=last 788 789 This allows you to access the final page of results conveniently, without 790 first having to determine how many pages there are. 791 792 Note that ``page`` *must* be either a valid page number or the value ``last``; 793 any other value for ``page`` will result in a 404 error. 794 787 795 ``django.views.generic.list_detail.object_detail`` 788 796 -------------------------------------------------- 789 797