[z3-five] Formlib and genuine add forms in Plone

Rob Miller ra at burningman.com
Tue Oct 17 19:25:52 CEST 2006


Dennis Schulz wrote:
> Hi,
> 
> I am currently learning how to do a content type with Formlib ( Five
> 1.4.1, Zope 2.9.5 and Plone 2.5.1 ) that should contain a genuine add 
> form, that means that the item is not created before entering any value 
> like in Archtypes (without portal factory).
> 
> http://plone.org/documentation/tutorial/using-zope-formlib-with-plone/formlib-and-content-types
> 
> I worked through this example. In the end the author states that "The
> only main missing piece (from formlib's perspective) here is using an
> auto-generated add form. While we can build those, they can't easily be
> hooked into Plone as Plone feels it needs to create the content first
> before displaying any forms."

there are two problems here that i'm aware of.  one, which is AT-specific, is 
that AT schemas expect to be rendered against an existing AT object, they 
don't work w/o one.  the other, which is not AT-specific, is that Plone's add 
menu automatically triggers the creation of an object of the specified type.

> How would it be if we don't use the Archetypes BaseContent class to
> build the ContentType (like in the tutorial), but the OFS.SimpleItem
> (there is an example in formlib/tests directory)?

i don't think this changes things too much.  formlib-based forms work w/o the 
need to be rendered against an existing object, as long as you're not using 
any interface generated by AT schema then it should be possible to generate a 
form before the object has been created.

> Would it be possible to auto generate a working add form?

yes.  for smooth integration it would require some changes to Plone's content 
adding infrastructure, so that when you use the menus to add a piece of 
content it is not assumed that the content should be created immediately.  it 
may be possible simply by developing a new version of the 'createObject.cpy' 
script, so that it checks a registry to see whether a given type should be 
created the old way, or if it should merely traverse to the addform view instead.

> Are there any
> examples where it actually really works?

yes.  there's a product called Fate in the AT svn repository on plone.org that 
generates working addforms for full AT schema driven content.  it does this by 
generating a "stub" object of the right type and rendering the schema against 
that stub.  the "real" object is not created until after the form is 
submitted.  IIRC, however, it did not handle the menu integration issue.  the 
solution i mentioned above would be a quick fix, however.

> I have looked at a few examples 
> now and everybody makes it a litte bit different..... does it make sense 
> to build upon Archetypes BaseContent or not?

depends.  building on BaseContent means you'll play better with the rest of 
Plone, b/c you'll still support such niceties as the reference engine and 
catalog multiplexing.  but AT objects are pretty heavy, if you need to produce 
hundreds of thousands of a particular type, you can make them much lighter and 
more efficient by not using AT.

> How do you make Content Types?

the bare minimum, i believe, is that you need to be a regular Zope object 
(e.g. by subclassing from SimpleItem) and you need to subclass DynamicType, 
PortalContent, and (arguably optional) CMFCatalogAware, all defined in 
CMFCore.  plus you need to register a TypeInfo object with the types tool.  it 
may be possible to do so with even less, but i believe this would be sufficient.

this may or may not belong on the five list, btw; it seems pretty 
Plone-specific to me, it may make more sense to have this on the plone-dev list.

-r



More information about the z3-five mailing list