New Plone product: roulationpolicy
Do you want to add a document to a folder that ends up (almost) at the top? Or do you want to roulate/rotate contents of a folder so a different one ends up on top each day or so? Zest Software presents a Plone product that does just that: roulationpolicy.
First: get the source at the Plone collective.
What the product does is best explained by the README.txt which I will add below. Look at roulation.txt for more doctests.
Usually when adding an object to a folder, this is added at the last position. This is not always wanted. You could use browser views or maybe SmartFolders to instead show the last item first, but this is not always the right solution. When you really want your new items to be added at (or near) the top, the roulationpolicy product is for you.
Adding content in a different position
This product uses a roulation policy when adding content to a folder. You can let content types implement the IRoulationContent interface. If you do not understand what I just said, ask a programmer. ;-) When such a content object is added to a folder, the item now gets added right below the top. This means, not at position zero (which is the top) but position one.
Roulating content to the bottom
A container (folder) can implement the IRoulationContainer interface. This means that every day the top most content object in that container is moved to the bottom.
Dependencies
- Zope 2.9 (or higher). The product uses zope 3 events, which means that it likely will not work with Zope 2.8.
- Archetypes (for the moveObjects* functions). I use the Plone 2.5 bundle containing that.
- For testing:
- Five: at least version 1.4 as that contains testbrowser.
- ATConttentTypes as we will use ATDocument and ATFolder to demonstrate our product. I use the Plone 2.5 bundle containing that.
Developers
See roulation.txt as a doctest on how to use this product. But basically it is this.
Choose content types that will implement our interfaces. For example, ATDocument can be roulation content.
>>> from zope.interface import classImplements >>> from Products.roulationpolicy.interfaces import IRoulationContent >>> from Products.ATContentTypes.content.document import ATDocument >>> classImplements(ATDocument, IRoulationContent)
This will make sure that new ATDocuments will be added right below the top of a folder.
Now you can let a folderish content type be a roulation container, for example ATFolder.
>>> from Products.roulationpolicy.interfaces import IRoulationContainer >>> from Products.ATContentTypes.content.folder import ATFolder >>> classImplements(ATFolder, IRoulationContainer)
Now add some code in a place that is locical to you that fires an event when the items in the folderish type need to be roulated:
>>> from zope.event import notify >>> from Products.roulationpolicy.events import ContainerRoulationEvent >>> notify(ContainerRoulationEvent(self.folder))
This will make sure that the top most item in self.folder gets moved to the bottom, making all the other items shift to the top.
Instead, you can also call a browser view that does this for you
>>> from Products.Five.testbrowser import Browser >>> browser = Browser() >>> browser.open(self.folder.absolute_url() + '/@@roulate_folder')