[Checkins] SVN: z3c.table/trunk/ Removed the advanced batching implementation as it is a helper function in z3c.batching now
Christophe Combelles
ccomb at free.fr
Sat Oct 11 07:27:15 EDT 2008
Log message for revision 92032:
Removed the advanced batching implementation as it is a helper function in z3c.batching now
Changed:
U z3c.table/trunk/CHANGES.txt
U z3c.table/trunk/setup.py
U z3c.table/trunk/src/z3c/table/batch.py
-=-
Modified: z3c.table/trunk/CHANGES.txt
===================================================================
--- z3c.table/trunk/CHANGES.txt 2008-10-11 11:24:15 UTC (rev 92031)
+++ z3c.table/trunk/CHANGES.txt 2008-10-11 11:27:15 UTC (rev 92032)
@@ -2,16 +2,15 @@
CHANGES
=======
-Version 0.5.1dev (unreleased)
------------------------------
+Version 0.6dev (unreleased)
+---------------------------
- Bugfix: CheckBoxColumn, ensure that we allways use a list for compare
selected items. It was possible that if only one item get selected
we compared a string. If this string was a sub string of another existing
item the other item get selected too.
-- Fixed advanced batching implementation, and extracted it in a separate
- function
+- Moved advanced batching implementation into z3c.batching
- Implemented GetAttrFormatterColumn. This column can be used for simple
value formatting columns.
Modified: z3c.table/trunk/setup.py
===================================================================
--- z3c.table/trunk/setup.py 2008-10-11 11:24:15 UTC (rev 92031)
+++ z3c.table/trunk/setup.py 2008-10-11 11:27:15 UTC (rev 92032)
@@ -23,7 +23,7 @@
setup (
name='z3c.table',
- version='0.5.1dev',
+ version='0.6dev',
author = "Stephan Richter, Roger Ineichen and the Zope Community",
author_email = "zope3-dev at zope.org",
description = "Modular table rendering implementation for Zope3",
@@ -65,7 +65,7 @@
),
install_requires = [
'setuptools',
- 'z3c.batching',
+ 'z3c.batching>=1.1.0',
'zope.component',
'zope.contentprovider',
'zope.dublincore',
Modified: z3c.table/trunk/src/z3c/table/batch.py
===================================================================
--- z3c.table/trunk/src/z3c/table/batch.py 2008-10-11 11:24:15 UTC (rev 92031)
+++ z3c.table/trunk/src/z3c/table/batch.py 2008-10-11 11:27:15 UTC (rev 92032)
@@ -21,125 +21,13 @@
from zope.traversing.browser import absoluteURL
from z3c.table import interfaces
+from z3c.batching.batch import first_neighbours_last
_ = zope.i18nmessageid.MessageFactory('z3c')
-def advanced_subset(batches, currentBatchIdx, prevBatchSize, nextBatchSize):
- """build an advanced subset from a large batch list
-
- This is used to display batch links for a table.
-
- arguments:
- batches: all the batches
- currentBatchIdx: index of the current batch
- prevBatchSize: number of displayed batches before the current batch
- nextBatchSize: number of displayed batches after the current batch
- return:
- an advanced reduced list of batches, with None as spaces
-
- Example:
- We build a large batch, and define a convenient display function::
-
- >>> from z3c.table.batch import advanced_subset as subset
- >>> batches = range(100) # it works with real batches as well
-
- We try to get subsets at different levels::
-
- >>> for i in range(0,6):
- ... subset(batches, i, 2, 2)
- [0, 1, 2, None, 99]
- [0, 1, 2, 3, None, 99]
- [0, 1, 2, 3, 4, None, 99]
- [0, 1, 2, 3, 4, 5, None, 99]
- [0, None, 2, 3, 4, 5, 6, None, 99]
- [0, None, 3, 4, 5, 6, 7, None, 99]
-
- >>> for i in range(93, 99):
- ... subset(batches, i, 2, 2)
- [0, None, 91, 92, 93, 94, 95, None, 99]
- [0, None, 92, 93, 94, 95, 96, None, 99]
- [0, None, 93, 94, 95, 96, 97, None, 99]
- [0, None, 94, 95, 96, 97, 98, 99]
- [0, None, 95, 96, 97, 98, 99]
- [0, None, 96, 97, 98, 99]
-
- Try with no previous and no next batch::
-
- >>> subset(batches, 0, 0, 0)
- [0, None, 99]
- >>> subset(batches, 1, 0, 0)
- [0, 1, None, 99]
- >>> subset(batches, 2, 0, 0)
- [0, None, 2, None, 99]
-
- Try with only 1 previous and 1 next batch:
-
- >>> subset(batches, 0, 1, 1)
- [0, 1, None, 99]
- >>> subset(batches, 1, 1, 1)
- [0, 1, 2, None, 99]
- >>> subset(batches, 2, 1, 1)
- [0, 1, 2, 3, None, 99]
-
- Try with incoherent values values::
- >>> subset(batches, 0, -4, -10)
- Traceback (most recent call last):
- ...
- AssertionError
- >>> subset(batches, 2000, 3, 3)
- Traceback (most recent call last):
- ...
- AssertionError
- """
- batchItems = []
- # setup some batches and indexes
- firstIdx = 0
- lastIdx = len(batches) - 1
- assert(currentBatchIdx >= 0 and currentBatchIdx <= lastIdx)
- assert(prevBatchSize >= 0 and nextBatchSize >= 0)
- prevIdx = currentBatchIdx - prevBatchSize
- nextIdx = currentBatchIdx + 1
- firstBatch = batches[0]
- lastBatch = batches[len(batches)-1]
-
- # add first batch
- if firstIdx < currentBatchIdx:
- batchItems.append(firstBatch)
-
- # there must probably be space
- if firstIdx + 1 < prevIdx:
- # we skip batches between first batch and first previous batch
- batchItems.append(None)
-
- # add previous batches
- for i in range(prevIdx, prevIdx+prevBatchSize):
- if firstIdx < i:
- # append previous batches
- batchItems.append(batches[i])
-
- # add current batch
- batchItems.append(batches[currentBatchIdx])
-
- # add next batches
- for i in range(nextIdx, nextIdx+nextBatchSize):
- if i < lastIdx:
- # append previous batch
- batchItems.append(batches[i])
-
- # there must probably be space
- if nextIdx + nextBatchSize < lastIdx:
- # we skip batches between last batch and last next batch
- batchItems.append(None)
-
- # add last batch
- if currentBatchIdx < lastIdx:
- batchItems.append(lastBatch)
- return batchItems
-
-
class BatchProvider(object):
- """Batch provider.
+ """Batch content provider.
A batch provider is responsible for rendering the batch HTML and not for
batching. The batch setup is directly done in the table. A batch provider
@@ -151,8 +39,7 @@
The batch acts like this. If we have more batches than
(prevBatchSize + nextBatchSize + 3) then the advanced batch subset is used.
- Otherwise, we will render all batch links.
-
+ Otherwise, we will render all batch links.
Note, the additional factor 3 is the placeholder for the first, current and
last item.
@@ -209,11 +96,11 @@
self.batchItems = self.batch.batches
else:
# switch to an advanced batch subset
- self.batchItems = advanced_subset(self.batches,
- self.batch.index,
- self.prevBatchSize,
- self.nextBatchSize,
- )
+ self.batchItems = first_neighbours_last(self.batches,
+ self.batch.index,
+ self.prevBatchSize,
+ self.nextBatchSize,
+ )
def render(self):
self.update()
More information about the Checkins
mailing list