From 70c1ee7c6807efe979da1a63e58270ca2ff1d966 Mon Sep 17 00:00:00 2001 From: Kernc Date: Sun, 14 Aug 2016 19:37:55 +0200 Subject: [PATCH] Fix edge condition with DEFAULT_PAGINATION and DEFAULT_ORPHANS Fixes https://github.com/getpelican/pelican/issues/1568 --- pelican/paginator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pelican/paginator.py b/pelican/paginator.py index 9aca550b..63dec893 100644 --- a/pelican/paginator.py +++ b/pelican/paginator.py @@ -35,7 +35,7 @@ class Paginator(object): "Returns a Page object for the given 1-based page number." bottom = (number - 1) * self.per_page top = bottom + self.per_page - if top + self.orphans >= self.count: + if top + self.orphans > self.count: top = self.count return Page(self.name, self.object_list[bottom:top], number, self, self.settings) @@ -50,7 +50,7 @@ class Paginator(object): def _get_num_pages(self): "Returns the total number of pages." if self._num_pages is None: - hits = max(1, self.count - self.orphans) + hits = max(1, self.count - self.orphans + 1) self._num_pages = int(ceil(hits / (float(self.per_page) or 1))) return self._num_pages num_pages = property(_get_num_pages)