Ticket #1795: paginator.py.diff

File paginator.py.diff, 1.0 KB (added by polarcowz@…, 19 years ago)

Paginator.py Patch

  • core/paginator.py

     
    1717    def __init__(self, query_set, num_per_page):
    1818        self.query_set = query_set
    1919        self.num_per_page = num_per_page
    20         self._hits, self._pages = None, None
     20        self._hits, self._pages, self._page_range = None, None, None
    2121        self._has_next = {} # Caches page_number -> has_next_boolean
    2222
    2323    def get_page(self, page_number):
     
    6363        if self._pages is None:
    6464            self._pages = int(ceil(self.hits / float(self.num_per_page)))
    6565        return self._pages
     66   
     67    def _get_page_range(self):
     68        """Returns a 1-based range of pages for iterating through within a template for loop."""
     69        if self._page_range is None:
     70            self._page_range = range(1, self._pages + 1)
     71        return self._page_range
    6672
    6773    hits = property(_get_hits)
    6874    pages = property(_get_pages)
     75    page_range = property(_get_page_range)
Back to Top