[Zope-CMF] set the id of a new cmf object in the factory method
Dieter Maurer
dieter@handshake.de
Mon, 16 Sep 2002 20:05:23 +0200
Aaron Payne writes:
> I'm trying to set the id of a new cmf object in the factory method and
> I'm hitting a wall.
> I need to get an attribute of the cmf site and then increment it by 1.
> In the factory method I have:
>
> def addBibliography(self, id , title='', bibliography_reference_id='',
> volume='', search_words=''):
> """Create an empty bibliography."""
>
> portal_url = getToolByName(self, 'portal_url')
> currentN=portal_url.bibliography_reference_count
> newN=currentN+1
> id='BIB'+str(newN)
> bibliography_reference_id=id
You should return the new id.
> ...
> When I attempt to add an object to a folder I receive an AttributeError.
We need "Error Type" (provided) and "Error Value" (missing) beside
the traceback (provided).
> Traceback (innermost last):
> ...
> 514, in constructInstance
> (Object: Bibliography)
> File /usr/local/zope/Zope2.5.1/lib/python/OFS/ObjectManager.py, line
> 232, in _getOb
"constructInstance" passed in an "id".
It expects either
* the the object is created with the given id
or
* the factory method returns the id it created the object with
You also need to use "_setObject" (or something similar) to
put the new object in the ObjectManager passed as first argument
to the factory method.
Dieter