Non-structural folders

by Martin Aspeli last modified Sep 12, 2009 09:13 AM
Sometimes you have a folderish item that is folderish as an implementation detail, but should not appear as a folder to the user. RichDocument is a prime example.

RichDocument has to be containerish so that it can contain files and attachments. Thus, it extends 'OrderedBaseFolder'. However, to the user, a document is not a folder.

Folders in Plone 2.1 get a few particular UI features:

o A 'contents' tab (unlike in Plone 2.0, there is no 'contents' tab on non-folders in Plone 2.1, because with the new 'actions' menu, there is much less need to use this view)

o An 'add item' menu to add items to the folder instead of an 'add to folder' menu to add sibling items in the parent folder.

o If you are in a parent folder's 'contents' tab and click a folder, you will see that folder's 'contents' tab, too.

Plone checks whether an item is a folder using the 'is_folderish' script. The expression 'object/is_folderish' (and its catalog metadata equivalent, which for efficiency reasons is implemented using ExtensibleObjectIndexWrapper in 'CMFPlone/CatalogTool.py') will evaluate to True if 'object' is a "structural folder" – that is, if it is a folder in the UI sense.

By default, all folders are structural, unless they implement the 'INonStructuralFolder' marker interface defined in 'CMFPlone/interfaces/NonStructuralFolder.py'. RichDocument does just this::

__implements__ = OrderedBaseFolder.__implements__ + \
ATDocument.__implements__ + \
(IRichDocument, INonStructuralFolder,)

And as if by magic, the folder acts like a folder no more.

Finally, because being able to choose a contained item as a default-view does not make sense for RichDocument, we use the method 'canSetDefaultView' from 'ISelectableBrowserDefault' (see the section on "dynamic views":dynamic-views) to explicitly disallow default views::

def canSetDefaultPage(self):
return False