[Zope-CMF] Re: Invoke factory?

Carl Rendell cer@sol43.com
Mon, 8 Jul 2002 19:29:52 -0700


On Monday, July 8, 2002, at 10:07  AM, Tres Seaver wrote:

> On Mon, 2002-07-01 at 12:18, Carl Rendell wrote:
>> I'll put this on the list for consumption...
>>
>> I've been working with an update package creates copies of all
>> items created with ZClass based products, and creates a new version
>> from a folder based equivalent. This is all done via a python
>> script implemented as an external method. It's being performed on a
>> rather old platforms - Zope 2.4.1/CMF 1.1 , Zope 2.4.1/CMF 1.2
>>
>> In my testing I found some strange behavior.. When attempting to
>> create a copy of the object using invokeFactory(), I would receive
>> the traceback listed below.
>>
>> After performing more testing, I found that invokeFactory() DOES
>> function in this environment, but ONLY when the portal_type is
>> configured to use a file based product. If the portal_type is
>> configured to use a ZClass based product, the traceback rears its
>> ugly head.
>>
>> At this point I understand the circumstances for the behavior, and
>> have a work-around so I'm not going into the problem any deeper. To
>> sum up my experience...
>>
>> someFolderObject.invokeFactory('myobjectid','portal_type')
>>
>> Is the preferred method for adding content, but can be a challenge
>> to use if your products are ZClass based.
>
> I can create ZClass-based content using invokeFactory using the
> latest CMF CVS.  In order to make it go, I delete the
> 'YourZClassHere_add' DTML method and replace it with a Python Script
> of the same name, whose body looks like::
>
>   ## Script (Python) "ZDocument_add"
>   ##bind container=container
>   ##bind context=context
>   ##bind namespace=
>   ##bind script=script
>   ##bind subpath=traverse_subpath
>   ##parameters=id, **kw
>   ##title=
>   ##
>   kw['id'] = id
>   context.ZDocument.createInObjectManager(id=id, REQUEST=kw)
>
>

Thanks Tres,

Yep, that will allow someFolderObject.invokeFactory() to work 
properly with ZClasses. However, if people are running on CMF 1.1 - 
as one of my sites was - then it is unlikely they would have 
changed their ZClass 'YourZClassHere_add' from dtml to a Python 
script.

That requirement - replace generated dtml for add method with 
python script - only appeared in notes for CMF 1.2 and beyond I 
believe. As a result, those on CMF 1.1 and using ZClasses will 
still run into the problem, but those using CMF 1.2 or later will 
not as they will have converted the _add_ method for their ZClass 
already.

Hopefully, this is a corner case now, and will no longer effect 
those using CMF as we've all upgraded beyond CMF 1.1 right ;-)

~C

Carl E. Rendell
Solution43
Information Distribution Consulting        |   "Ahhhh the power of
cer@sol43.com                              |    acquisition"  - Chef Z