[Zope-CMF] adding a type with a new factory method

Florent Guillaume fg@nuxeo.com
Sat, 20 Jul 2002 15:43:50 +0000 (UTC)


Karl Anderson  <kra@monkey.org> wrote:
> I'm trying to create a new type based on an existing one (CMFPost,
> part of CMFForum).  
> 
> Right now, I'm only trying to change the factory method.  So, I copied
> the CMFPost type to MyCMFPost, and changed the factory method to
> "myAddPost".  To create myAddPost, I added an External Method to the
> portal root, adapted from CMFPost.addPost, the old factory method (in
> the Python product).
> 
> However, this fails, apparently because the External Method is called
> differently - self isn't the container.  I couldn't use a
> Script(Python), because I can't call _setObject from it.
> 
> I finally got this working (so far) by adding a keyword argument called
> 'thecontainer' to the External Method, and having the skin that the
> MyCMFPost-adding action uses pass its context as the 'thecontainer'
> argument to context.invokeFactory (I couldn't use 'container', because
> PortalTypes.constructContent() complained about extra values for that
> keyword argument, which I still don't understand).
> 
> Am I going about this the right way?  It seems wrong that I have to
> pass the container explicitly.
> 
> Is there an example of changing a factory method?  Should I give up
> and subclass before I run into real problems?

Usually my factory method are in the product, not in external methods,
so I don't know what's your problem exactly. Could you post your
problematic code?

As for external methods, they are first call with exactly the
arguments passed from the caller, and if this gives a TypeError the
call is retried with the current context as a first argument. This
makes it possible to get to the context from an external method if it
has a fixed number of arguments, and the first one is "context" (I
really wish we stopped using "self" for that, we're not in a class).

Florent

-- 
Florent Guillaume, Nuxeo (Paris, France)
+33 1 40 33 79 87  http://nuxeo.com  mailto:fg@nuxeo.com