Batching facilities used in Plone.
Project description
Welcome to Plone batching’s documentation!
This package includes facilities for creating a batched sequence.
It originated from the the PloneBatch module written for Plone which in itself has been based on Zope2’s ZTUtils.Batch.
Changelog
1.1.7 (2021-03-02)
New features:
Include request form parameters from parent request to allow batching in plone.app.standardtiles and filtering with collective.collectionfilter. [agitator] (#26)
1.1.6 (2020-04-20)
Bug fixes:
Minor packaging updates. (#1)
1.1.5 (2018-11-29)
Bug fixes:
Do not show batch navigation for single page with orphan. [maurits] (#9)
1.1.4 (2018-09-27)
Bug fixes:
Fix navlist different in Python2 and Python 3 (Refs. #21) [ale-rt]
Python 3 fixes. [thet]
1.1.3 (2018-06-04)
New features:
Pagination: made label and arrows easier to customise. [iham]
1.1.2 (2017-07-20)
Bug fixes:
Added missing Zope2 dependency. [davisagli]
1.1.1 (2016-08-12)
Fixes:
Use zope.interface decorator. [gforcada]
1.1.0 (2016-02-12)
New:
Refactor batchnavigation HTML layout to use nav/ul/li elements instead of div/span. [davilima6]
Switches deprecated listingBar CSS class to pagination. [davilima6]
Make ellipses stylable and provide more CSS hooks to pagination markup. [davilima6]
1.0.8 (unreleased)
New:
Make ellipses stylable and provide more CSS hooks to pagination markup. This also deprecates the CSS class listingBar in favor of more commonly used pagination, which will be the canonical one in Plone 5.0.2 and up. [davilima6]
1.0.7 (2016-01-08)
Fixes:
Fixed missing test in released package. [thet]
1.0.6 (2016-01-08)
New:
Introduce a “omit_params” option for the make_link method and filter out ajax_load by default. When loading the contents with batchnavigation via ajax, it doesn’t render the links with ajax_load enabled, which would probably lead to usability troubles. [thet]
Fixes:
PEP 8, UTF 8 headers, docs cleanup. [thet]
1.0.5 (2015-07-18)
Make sure pagenumber value is not bigger that numpages or it fails in previous_pages when using orphan [gbastien]
Allow orphan size to be equal to batch size. This allows the edge case of batch size 0 with default orphan size 0. [do3cc]
1.0.4 (2015-04-28)
Fix lastpage computation with orphaning [gbastien]
1.0.3 (2015-02-20)
Fix issue with orphaning [do3cc]
1.0.2 (2014-04-13)
Fix issue where a start >= end will always return last item. https://dev.plone.org/ticket/13880[thepjot]
Fix multiple_pages if the length of the sequence is exactly the page length. [gaudenz]
1.0.1 (2014-01-27)
Fix issue with sequences when the reported length was different than len() iteration would return the full unbatched sequence. [alecm]
1.0 (2013-05-23)
Use index instead of template attribute in BatchView to be able to customize only the template. [vincentfretin, thomasdesvenain]
Fixed wrong msgid for ‘First item’. [vincentfretin]
1.0b1 (2013-01-17)
Nothing changed yet.
1.0a1 (2012-04-25)
Factored out Plone batching implementation to seperate egg (PLIP #12235) [tom_gross]
Usage
A batch defined in plone.batching usually consists of two things:
A batch object. This is usually a wrapper for a sequence, which provides slices of information.
A batch view. This is needed for display. It contains links to navigate to the slices defined in 1.
Both elements can be defined and accessed in Python code AND pagetemplates.
Usage in Python code
A batch is instantiated like this:
>>> from plone.batching import Batch >>> batch = Batch(range(100), size=15, orphan=10)
This generates 5 subbatches with 15 items from the sequence [0, 1, …, 99] and one subbatch with the last 25 items (including 10 orphaned items). For a detailed description of available parameters for a batch look at the API of the BaseBatch class.
Another way to instaniate a batch is like this:
>>> batch = Batch.fromPagenumber(range(100), pagesize=15, pagenumber=1)
This results in 6 batches with 15 items and one batch with the last 10 items. This way of creating a batch is meant as a short cut and does not support all the options the canonical constructor supports.
For big sequences there is another base class provided by the package: QuantumBatch. This batch generates quantum leaps for quicker navigation.
>>> from plone.batching.batch import QuantumBatch >>> qb = QuantumBatch(range(1000), 10, start=500, quantumleap=1) >>> qb.leapforward [69, 84] >>> qb.leapback [18, 33]
It is possible to navigate the batch stored in the two attributes leapback and leapforward with 5 clicks.
Usage in Views
Plone.batching comes with a customizable batch View batchnavigation with the view class BatchView. The view comes with a template. All you have to do, if you want to customize it, is to override the make_link-method. This method should return a string with the link to the given pagenumber. Here is an example from the folder_contents implementation in plone.app.content:
>>> from plone.batching.browser import BatchView >>> from ZTUtils import make_query >>> class MyBatchView(BatchView): ... def make_link(self, pagenumber): ... batchlinkparams = self.request.form.copy() ... return '%s?%s' % (self.request.ACTUAL_URL, ... make_query(batchlinkparams, {'pagenumber': pagenumber}))
One thing you have to keep in mind is to call the batch view with a batch as the first argument.
>>> from Products.Five import BrowserView >>> class MyContentView(BrowserView): ... def batch(self): ... " " # see above how a batch is defined ... ... def batching(self): ... return MyBatchView(self.context, self.request)(self.batch)
Now you can use this in the template of your view.
<div tal:replace="structure view/batching" />
Incompatibilities
XXX __len__ method
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for plone.batching-1.1.7-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93cb27f3feb238aab9f77f126e0b5ded8ae4bba9aab70fc3183ff610108a011b |
|
MD5 | 7178b2388231dd1bd5ee114c62e56609 |
|
BLAKE2b-256 | f2a29e2d80ebc43153df3c924101674fa669033922e6fdc6b43ebd9fb2c60f84 |