plone/plone.app.contentlisting — pull request #4 by mauritsvanrees (2012-12-27 11:18:36+00:00)
Title: Maurits 12973 batching

This is for [ticket 12973](https://dev.plone.org/ticket/12973).

When batch=True we now return a Batch object, so you do not get an AttributeError when using code like this in a template:

```

```

Batching was already used in a similar way earlier, but that was reverted in pull request #2, apparently to avoid some problems. The issue I am trying to solve already existed before that pull request was applied, so it did not cause it.

My pull request works fine for the above template snippet, but it could cause some tests to fail, which may or may not be bad in practice. But I cannot run the tests, as for some reason the test setup completely goes wrong:

```python
$ bin/test -s plone.app.contentlisting
Running plone.app.contentlisting.tests.base.ContentListing:Functional tests:
Set up plone.testing.zca.LayerCleanup in 0.000 seconds.
Set up plone.testing.z2.Startup in 0.244 seconds.
Set up plone.app.testing.layers.PloneFixture Traceback (most recent call last):
File "/Users/mauritsvanrees/shared-eggs/zope.testing-3.9.7-py2.7.egg/zope/testing/testrunner/runner.py", line 366, in run_layer
setup_layer(options, layer, setup_layers)
File "/Users/mauritsvanrees/shared-eggs/zope.testing-3.9.7-py2.7.egg/zope/testing/testrunner/runner.py", line 628, in setup_layer
setup_layer(options, base, setup_layers)
File "/Users/mauritsvanrees/shared-eggs/zope.testing-3.9.7-py2.7.egg/zope/testing/testrunner/runner.py", line 628, in setup_layer
setup_layer(options, base, setup_layers)
File "/Users/mauritsvanrees/shared-eggs/zope.testing-3.9.7-py2.7.egg/zope/testing/testrunner/runner.py", line 633, in setup_layer
layer.setUp()
File "/Users/mauritsvanrees/shared-eggs/plone.app.testing-4.2.1-py2.7.egg/plone/app/testing/layers.py", line 104, in setUp
self.setUpDefaultContent(app)
File "/Users/mauritsvanrees/buildout/python2.7/parts/opt/lib/python2.7/contextlib.py", line 35, in __exit__
self.gen.throw(type, value, traceback)
File "/Users/mauritsvanrees/shared-eggs/plone.testing-4.0.7-py2.7.egg/plone/testing/z2.py", line 255, in zopeApp
app.REQUEST.close()
File "/Users/mauritsvanrees/shared-eggs/Zope2-2.13.19-py2.7.egg/ZPublisher/BaseRequest.py", line 218, in close
notify(EndRequestEvent(None, self))
File "/Users/mauritsvanrees/shared-eggs/zope.event-3.5.2-py2.7.egg/zope/event/__init__.py", line 31, in notify
subscriber(event)
File "/Users/mauritsvanrees/shared-eggs/zope.component-3.9.5-py2.7.egg/zope/component/event.py", line 24, in dispatch
zope.component.subscribers(event, None)
File "/Users/mauritsvanrees/shared-eggs/zope.component-3.9.5-py2.7.egg/zope/component/_api.py", line 136, in subscribers
return sitemanager.subscribers(objects, interface)
File "/Users/mauritsvanrees/shared-eggs/zope.component-3.9.5-py2.7.egg/zope/component/registry.py", line 321, in subscribers
return self.adapters.subscribers(objects, provided)
AttributeError: adapters

Tearing down left over layers:
Tear down plone.testing.z2.Startup in 0.014 seconds.
Tear down plone.testing.zca.LayerCleanup in 0.004 seconds.
```

This is on my branch, but also when using master or even when simply using the lastest release. This is in the core-dev 4.2 buildout.

Note that an alternative approach would be to add batching properties to the ContentListing class or to a child class:

```python
@property
def pagenumber(self):
"""Page number for batching.
"""
return self._basesequence.pagenumber
```

That would need to be done for at least fourteen properties and those would need security statements or would need other means of allowing to access those properties in a template. Note that PloneBatch.py has ```__allow_access_to_unprotected_subobjects__ = 1``` for this.