[Zope-CMF] How to add a non-empty instance of a content type

Dieter Maurer dieter@handshake.de
Tue, 10 Jun 2003 20:05:01 +0200


Sam Brauer wrote at 2003-6-10 10:51 -0400:
 > ...
 > I know you can change the "immediate view" to the edit form instead of 
 > the metadata form.  But what I'd really like to be able to do is present 
 > the user with a customized version of the edit form that includes an ID 
 > field, and not actually store an object until the user submits the edit 
 > form.  At that time, besides doing any type-specific validation, I would 
 > need to make sure that the ID is valid.  Then if there's anything 
 > invalid, I would re-render the edit form with the data from the request 
 > and some error messages.

You would need to customize the UI, more precisely, the part
dealing with object creation. Instead of asking for type
and id on one form and then switching to the creation action,
you would only ask for the type, then go to a second form
asking for id and all relevant information and only then
transfer to the creation action.
This action would create the object and then update its content
with the collected information, in a single transaction.

 > My custom types can do the validation and form re-rendering, but they 
 > can only edit existing objects.

I solved this problem by creating a temporary object, loosely
mapped into the Zope hierarchy (via "__of__").
When everything was right, the object was finally embedded
into the site with "_setObject".
Adapting this approach for CMF would require some non-trivial
changes.

 > My types have a factory method that 
 > takes as arguments an ID and an optional REQUEST.  I'm guessing there's 
 > some way a script could call that constructor method and pass a REQUEST 
 > to it, but I haven't been able to figure out the proper way to do that yet.

The "constructContent" method takes arguments
"type_name", "destinationFolder", "id", "RESPONSE".
Any additional arguments are passed on to your factory.

 > Can anyone offer any advice on handling an "add" form that doesn't store 
 > a new object until the add form has been successfully submitted?

"Plone" solved this problem in a more general way.
Maybe, you can learn from their code.


Dieter