Package: collective - CMFViews
a test of SfIndex product
Sourceforge Info
| Project Name: | collective |
| Package Name: | CMFViews |
| Files Page: | |
| Browse CVS: | http://cvs.sourceforge.net/viewcvs.py/collective/CMFViews/ |
Package README (CVS ver. 1.1)
CMFViews
========
This package provides a ``View Registry`` to be used by Page Templates
and derived types to easily cache view information and move logic out
of templates.
It works by adding a ``view`` variable to Page Template's context,
which is a ``ViewFactory`` bound to the ``portal_type`` and template
id.
Basic Operation
---------------
There is a simple example, built for Plone's ``folder_contents`` view
in ``examples/Folder.py``.
Basically, you build a simple class with some methods (you can use
Python 2.2+ features like descriptors because this class won't be
persisted), the methods may be named anyway you like it.
In the example, we build a big dict with the information about the
items inside a folder, which is used for the ``folder_contents``
view. We also try to cache this dict using some parameters that may
change for each request, like the ``b_start`` variable, which is used
for batching the listing.
**IMPORTANT**: If you want to use caching, you must do a couple
things:
- First, you have to bind your template to a Cache Manager (like the
Ram Cache Manager).
- Second, you must **not** cache acquisition-wrapped objects. This
is **very** important because the Cache Manager will **not** cache the
objects and will **not** complain!
- Third, read the example code, as it's very self-explanative.
Once you created your View class, you just need to register it using
``registerView(<View class>, <portal_type>, <template id (optional>)``
as on the example.