[Zope] Why can't I use a method of an objectmanger I am trying to add to ?
Jens Vagelpohl
jens@zope.com
Thu, 13 Sep 2001 08:08:16 -0400
max,
inside a factory method like your manage_addMessageAction "self" is not=20=
necessarily what you might expect. you can get more details by using the=20=
debugger to step through the code inside of it.
i have come up against a similar problem and solved it by calling...
self =3D self.this()
before "using" self inside the factory method. i would place this call=20=
right before you call self._getNewId().
this is usually done in factory methods for user folders because they =
set=20
an attribute on the folder they are in (which is "self" in their factory=20=
methods) and must ensure that the attribute does indeed get set in this=20=
folder and nowhere else.
hth
jens
On Thursday, September 13, 2001, at 07:47 , Max M=F8ller 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 =3D '%012d' % self._newId
> self._newId +=3D 1
> self._p_changed =3D 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=3D'No title',
> comment=3D'No comment',
> author=3D'No author',
> email=3D'',
> parent=3DNone,
> REQUEST=3DNone, RESPONSE=3DNone):
>
> "Adds a message to the objectmanager"
>
> id =3D 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=20=
> 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,=20=
> line
> 106, in manage_addMessageAction
>
> AttributeError: (see above)
>
> ------------------------------------------------------
>
> line 106 being "id =3D self._getNewId()"
>
> "manage_addMessageAction" is registered as a constructor. When it is =
being
> called from an ObjectManager, isn't the objectmanager passed to this=20=
> 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 )