Skip to content

Commit

Permalink
Fix issue with orphaning
Browse files Browse the repository at this point in the history
Orphaning did not work...
Added a test and an assertion for funny folks
trying to have orphan ranges higher than batch size.
  • Loading branch information
do3cc committed Jan 27, 2015
1 parent 99779f8 commit d6b8296
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Expand Up @@ -4,7 +4,8 @@ Changelog
1.0.3 (unreleased)
------------------

- Nothing changed yet.
- Fix issue with orphaning
[do3cc]


1.0.2 (2014-04-13)
Expand Down
4 changes: 3 additions & 1 deletion plone/batching/batch.py
Expand Up @@ -31,6 +31,8 @@ def __init__(self, sequence, size, start=0, end=0, orphan=0, overlap=0,
overlap - the number of overlapping elements in each batch
pagerange - the number of pages to display in the navigation
"""
assert orphan < size, "Having an orphan size, higher than batch size" \
" is undefined"
start += 1
self._sequence = sequence
self._size = size
Expand Down Expand Up @@ -155,7 +157,7 @@ def lastpage(self):
""" Last page of batch
"""
pages = self.sequence_length / self.pagesize
if self.sequence_length % self.pagesize:
if (self.sequence_length - self.orphan) % self.pagesize:
pages += 1
return pages

Expand Down
7 changes: 7 additions & 0 deletions plone/batching/tests.py
Expand Up @@ -97,6 +97,13 @@ def test_lastpage(self):
lastbatch = BaseBatch(range(20), 5, start=batch.last)
self.assertTrue(lastbatch.islastpage)

def test_lastpage_with_orphans(self):
batch = BaseBatch(range(11), 10, orphan=1)
self.assertEqual(1, batch.lastpage)
batch = BaseBatch(range(109), 10, orphan=9)
self.assertEqual(10, batch.lastpage)
self.assertRaises(AssertionError, BaseBatch, [], 10, orphan=20)

def test_items_not_on_page(self):
batch = BaseBatch(range(20), 5, start=5)
self.assertEqual(batch.items_not_on_page,
Expand Down

1 comment on commit d6b8296

@mister-roboto
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TESTS FAILED
Mr.roboto url : http://jenkins.plone.org/roboto/get_info?push=22ebc95a253c459ba481c665f618f8d0
plone-4.3-python-2.6 [FAILURE]
plone-4.3-python-2.7 [FAILURE]
plone-5.0-python-2.7 [SUCCESS]

Please sign in to comment.