Skip to content

Commit

Permalink
Really need to compute _pagenumber when using orphan
Browse files Browse the repository at this point in the history
  • Loading branch information
gbastien committed Jul 9, 2015
1 parent 760cf78 commit 18cc2b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
19 changes: 10 additions & 9 deletions plone/batching/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,23 @@ def initialize(self, start, end, size):
self.end = end

self.first = max(start - 1, 0)
if self.beyond:
self.first = self.end
self.length = self.end - self.first

self.last = self.sequence_length - size

# Set up the total number of pages
self.numpages = calculate_pagenumber(
self.sequence_length - self.orphan, self.pagesize, self.overlap)

if self.beyond:
self.first = self.end
# Make sure current page number is not > numpages
self._pagenumber = self.numpages
else:
# Set up the current page number
self._pagenumber = calculate_pagenumber(
self.start, self.pagesize, self.overlap)
# Set up the current page number
self._pagenumber = calculate_pagenumber(
self.start, self.pagesize, self.overlap)

self.length = self.end - self.first
# Make sure self._pagenumber is <= self.numpages
if self._pagenumber > self.numpages:
self._pagenumber = self.numpages

@property
def navlist(self):
Expand Down
10 changes: 5 additions & 5 deletions plone/batching/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ def test_multiple_pages_longer(self):
def test_pagenumber_never_over_numpages(self):
"""computed _pagenumber is never > numpages, this
makes previous_pages not fail."""
batch = BaseBatch([1, 2, 3, 4, 5, 6, 7], 3, 8)
batch = BaseBatch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3, 9)
self.assertEquals(batch.previous_pages, [1, 2, 3])
self.assertEquals(batch._pagenumber, 4)
# works especially with orphan
batch = BaseBatch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3, 9, orphan=2)
self.assertEquals(batch.previous_pages, [1, 2])
self.assertEquals(batch._pagenumber, 3)
# works especially with orphan
batch = BaseBatch([1, 2, 3, 4, 5, 6, 7], 3, 8, orphan=2)
self.assertEquals(batch.previous_pages, [1])
self.assertEquals(batch._pagenumber, 2)


class TestQuantumBatch(unittest.TestCase):
Expand Down

0 comments on commit 18cc2b7

Please sign in to comment.