max, inside a factory method like your manage_addMessageAction "self" is not necessarily what you might expect. you can get more details by using the debugger to step through the code inside of it. i have come up against a similar problem and solved it by calling... self = self.this() before "using" self inside the factory method. i would place this call right before you call self._getNewId(). this is usually done in factory methods for user folders because they set an attribute on the folder they are in (which is "self" in their factory methods) and must ensure that the attribute does indeed get set in this folder and nowhere else. hth jens On Thursday, September 13, 2001, at 07:47 , Max Møller Rasmussen wrote:
I have an objectmanager that implements:
def _getNewId(self): """ generates a new unique id for a message get new id and make a zero-padded string """ # 12 chars long, 999,999,999,999 messages max in one discussion! newID = '%012d' % self._newId self._newId += 1 self._p_changed = 1 return newID
And it works nicely if I call it directly.
But when I try to call the method from an object being added to the objectmanager like this:
------------------------------------------------------
def manage_addMessageAction(self, title='No title', comment='No comment', author='No author', email='', parent=None, REQUEST=None, RESPONSE=None):
"Adds a message to the objectmanager"
id = self._getNewId()
.... etc.
------------------------------------------------------
I get an error:
Error Type: AttributeError Error Value: _getNewId
Traceback (innermost last):
File C:\zope\zope240\lib\python\ZPublisher\Publish.py, line 223, in publish_module
File C:\zope\zope240\lib\python\ZPublisher\Publish.py, line 187, in publish
File C:\zope\zope240\lib\python\Zope\__init__.py, line 226, in zpublisher_exception_hook
File C:\zope\zope240\lib\python\ZPublisher\Publish.py, line 171, in publish
File C:\zope\zope240\lib\python\ZPublisher\mapply.py, line 160, in mapply (Object: manage_addMessageAction)
File C:\zope\zope240\lib\python\ZPublisher\Publish.py, line 112, in call_object (Object: manage_addMessageAction)
File C:\zope\zope240\lib\python\Products\mxm_Discuss\mxm_Message.py, line 106, in manage_addMessageAction
AttributeError: (see above)
------------------------------------------------------
line 106 being "id = self._getNewId()"
"manage_addMessageAction" is registered as a constructor. When it is being called from an ObjectManager, isn't the objectmanager passed to this unbound method?
If so, why can't it find "_getNewId()"
Regards Max M
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )