[Zope-CMF] Plone content basics

Geoff Davis geoff@geoffdavis.net
Tue, 9 Jul 2002 23:24:47 -0400


For all you Plonistas out there,

I have started delving into the innards of Plone.  It looks like you all
have done a lot of really thoughtful things to configure the CMF in a saner
way and to enhance the existing foundation, but there are some things that
are leaving me scratching my head.  Before I start hacking my own Plone
products (I'm planning to do a Plone-style version of Alan Runyan's CMF
Employment Objects as an initial learning experience), I want to make sure I
understand what's going on.  At a minimum, having a good understanding of
the fine points of the code will let me write decent comments in the
Employment Objects example.

As a starting point I started dissecting news items.  The first thing I note
is that validation and some content modification are now handled by skin
scripts rather than by the NewsItem class.  At first glance it's a little
weird to move this stuff outside the class, but upon further reflection I am
guessing that your motives are as follows:

* /plone/skins/plone_scripts/validate_newsitem.py: Validation, particularly
error messages, is portal-specific and best handled by a skin-type object.
Putting validation in a skin means one can have a very simple NewsItem class
that never changes.

* /plone/skins/plone_scripts/newsitem_edit.py: This skin invokes the
validation script, the NewsItem.edit() method, and the portal's edit
metadata service.  Basically this skin serves to glue together several
different services.  Putting this kind of thing outside the class means that
(1) the NewsItem class doesn't need to know much about the portal, (2) some
basic navigation choices (e.g. what happens when there are errors, what
happens after the various edit methods are invoked) are handled in a skin
rather than in the NewsItem class.

These choices seem pretty reasonable, though there are a few downsides:
* The newsitem's various methods are spread out over lots of different
files, though I guess there's not much one can do about that.
* The validation script builds and destroys a form validator object every
time it is invoked, which seems really inefficient.  That looks relatively
straightforward to work around by building a validator repository somewhere
from which one pulls the needed validator.

Am I on the right track so far?  If so, the next thing I'm trying to figure
out is what the code for these two scripts is doing.

* /plone/skins/plone_scripts/validate_newsitem.py: This seems like a pretty
straightforward usage of Formulator's various validators.  I don't know the
API, but it doesn't look too involved.

* /plone/skins/plone_scripts/newsitem_edit.py: There are a few funky things
here.
    - It looks like first you autogenerate an ID if none is present.
    - Next you validate the form and send things back if they fail
validation.
    - Next you set/modify the metadata.  This I'm a little mystified by:
First, the newsitem_edit_form doesn't have any metadata fields on it -- I
assume this section is in the code to allow one to add metadata fields to
newsitem_edit_form (in a way that doesn't contain all the assumptions of
metadata_edit when values are None)?  Second, when would a news_item ever
_not_ have an extended_edit attribute?  And when would the extended_edit
method ever return a non-empty response?  Maybe if an exception were thrown?
Under any other circumstances?
    - Next you invoke the NewsItem object's edit method.  I don't understand
the comment about why this is called after the metadata modification, but
after poking around document_edit.py (which has a less cryptic comment) it
looks like this is this a general concern for things that inherit from
Document.
    - Next you see if the object's ID has been changed and deal accordingly.
    - Next you create add an annotation to the current ZODB transaction for
later use in an Undo screen
    - Finally you redirect to the new news item's view screen with a useful
status message.

Is there anything I have missed?  Any other comments?


Geoff Davis
http://www.geoffdavis.net