Ticket #6997: paginator2.diff

File paginator2.diff, 1.4 KB (added by simeon, 16 years ago)

Updated patch to hande orphans param, match svn head and add tests

  • django/core/paginator.py

     
    5353    def _get_num_pages(self):
    5454        "Returns the total number of pages."
    5555        if self._num_pages is None:
    56             hits = self.count - 1 - self.orphans
    57             if hits < 1:
    58                 hits = 0
    59             if hits == 0 and not self.allow_empty_first_page:
     56            if self.count - self.orphans <= 0 and not self.allow_empty_first_page:
    6057                self._num_pages = 0
    6158            else:
     59                hits = self.count - 1 - self.orphans
     60                if hits < 0:
     61                    hits = 0
    6262                self._num_pages = hits // self.per_page + 1
    6363        return self._num_pages
    6464    num_pages = property(_get_num_pages)
  • tests/modeltests/pagination/models.py

     
    140140>>> p.end_index()
    1411415
    142142
     143# Check edge case: with allow_empty_first_page=False and list len=1, num_pages should be 1
     144>>> paginator = Paginator([1], 5, 0, False)
     145>>> paginator.count
     1461
     147>>> paginator.num_pages
     1481
     149>>> paginator.page_range
     150[1]
     151
     152
    143153################################
    144154# Legacy API (ObjectPaginator) #
    145155################################
Back to Top