zeam.utils.batch

Generic Batch support for Zope
Download

zeam.utils.batch Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Publisher Name:
  • Sylvain Viollon
  • Publisher web site:
  • http://github.com/thefunny42/

zeam.utils.batch Tags


zeam.utils.batch Description

Generic Batch support for Zope zeam.utils.batch is a package that provides a batch functionality for Zope 2, Zope 3 and Grok.ExampleA very straightforward example. We need to define a context to work on:>>> import grokcore.view as grok>>> from persistent import Persistent>>> from zope.component import queryMultiAdapter>>> from zeam.utils.batch import batch>>> from zeam.utils.batch.interfaces import IBatching>>> class Content(Persistent):... passAnd now, you can define a view which use a batch, and render it:>>> class MyViewClass(grok.View):... grok.context(Content)...... def update(self):... fulllist = ... self.myitems = batch(... fulllist , count=3, name='nbs', request=self.request,... factory=lambda x: str(x))...... self.batch = queryMultiAdapter(... (self.context, self.myitems, self.request),... IBatching)()...... template = grok.PageTemplate('''... < tal:navigation tal:replace="structure view/batch" / >... < span tal:content="item" tal:repeat="item view/myitems" / >... < tal:navigation tal:replace="structure view/batch" / >... ''')And this work:>>> from grokcore.component import testing>>> testing.grok_component("view", MyViewClass)True>>> from zope.publisher.browser import TestRequest>>> request = TestRequest()>>> root = getRootFolder()>>> root = Content()>>> myobj = root>>> view = queryMultiAdapter((myobj, request), name="myviewclass")>>> "batchNav" in view()TrueAPIbatch This object implements the batch. The batch object is instanciated with the following arguments: * a list of the objects to batch * the request * the number of items per page * a name (optional) * a factory that will be passed each item before each iteration (optional) The batch is an iterable object behaving like a list. It only gives access to the set of objects for the current page. It provides the number of pages generated and the current position. Please refer to the interface, for more information. A multi adapter providing IBatching can render the batch. It adapts the context, the batch object and the request. The __call__ method of this component will return a snippet of HTML containing basic controls for your batch: a next and previous link and a direct access to the other pages. Requirements: · Python What's New in This Release: · Add a __len__ method do a batch object, which returns the number of objects viewable via this current batch. Like this, it can be used with tal:condition in templates. · An option keep_form_data on the view prevent to include posted form data in generated links (sometime you want them, some other you don't).


zeam.utils.batch Related Software