Ticket #3391: generic_object_list.2.patch

File generic_object_list.2.patch, 2.4 KB (added by Max Derkachev <mderk@…>, 18 years ago)

the better patch

  • django/core/paginator.py

     
    1919        self.query_set = query_set
    2020        self.num_per_page = num_per_page
    2121        self.orphans = orphans
    22         self._hits = self._pages = None
     22        self._hits = self._pages = self._page_numbers = None
    2323
    2424    def validate_page_number(self, page_number):
    2525        try:
     
    8282            if hits < 1:
    8383                hits = 0
    8484            self._pages = hits // self.num_per_page + 1
     85            self._page_numbers = range(1, self._pages+1)
    8586        return self._pages
     87   
     88    def _get_page_numbers(self):
     89        if self._page_numbers is None:
     90            self._get_pages()
     91        return self._page_numbers   
    8692
    8793    hits = property(_get_hits)
    8894    pages = property(_get_pages)
     95    page_numbers = property(_get_page_numbers)
  • django/views/generic/list_detail.py

     
    4848                object_list = []
    4949            else:
    5050                raise Http404
     51               
    5152        c = RequestContext(request, {
    5253            '%s_list' % template_object_name: object_list,
    5354            'is_paginated': paginator.pages > 1,
     
    5859            'next': page + 1,
    5960            'previous': page - 1,
    6061            'pages': paginator.pages,
     62            'page_numbers': paginator.page_numbers,
     63            'page_first_item_num': paginator.first_on_page(page - 1),
     64            'page_last_item_num': paginator.last_on_page(page - 1),
    6165            'hits' : paginator.hits,
    6266        }, context_processors)
    6367    else:
  • docs/generic_views.txt

     
    754754
    755755    * ``pages``: The total number of pages, as an integer.
    756756
     757    * ``page_numbers``: The list of page numbers (integers).
     758
     759    * ``page_first_item_num``: The number of the first item on the page.
     760
     761    * ``page_last_item_num``: The number of the last item on the page.
     762
    757763    * ``hits``: The total number of objects across *all* pages, not just this
    758764      page.
    759765
Back to Top