[Zope-CMF] Add content programmatically
Kevin Teague
kteague@bcgsc.bc.ca
Tue, 28 May 2002 14:16:49 -0700
What you want to do is perform actions like automatically adding default
objects to a new folder after the object has been initialized and stored
in the Zope Object Database.
At the point that __init__ is called, the object is just residing in
memory, and isn't yet 'set' into the databse. This means that anything
that relies on acquisition won't work (like the invokeFactory method).
What you might want to do is call invokeFactory in your
manage_addCMFExtNews method, after something like "self._setObject(id,
ob)" has been called.
Keller Nicolas wrote:
> Hi!
>
> For hours I've tried to accomplish the following: I've got a CMF
> product that holds content and acts as an folder. What I want to
> to now is to add a file (eg. an empty image object) after the object
> was created. I think the following code is not totally wrong (at
> least I hope so for my ego :)) but it always comes up with an
> "AttributeError: portal_types" - Traceback.
>
> ----------------------------- cutting -------------------------------
>
> class CMFExtNews(PortalFolder, PortalContent, DefaultDublinCoreImpl):
>
> meta_type = 'CMFExtNews'
>
> def __init__(self, id, title=''):
> DefaultDublinCoreImpl.__init__(self)
> self.id = id
> self.title = title
> self.invokeFactory('Image', 'img') <------ The bad one
>
> ----------------------------- cutting -------------------------------
>
> Without the 'self.invokeFactory('Image', 'img')'-line the product
> works perfect but I'm really hopeless on this one.
>
> Any hints?
>
> Bye,
>
> Nicolas Keller
--
-- Kevin Teague
Genomics Web Developer
BC Genome Sciences Centre
http://www.bcgsc.ca