[Zope] Zope context
DA Loeffler
David.Loeffler@bristol.ac.uk
Mon, 5 Aug 2002 16:42:06 +0100 (BST)
I got round this one by actually passing the context to the class
constructor as an argument, and storing it as self.context with the
class's __init__ method. You can then freely call things on it, in my
case
for r in self.context.someSQLMethod():
or whatever. Since python functions are call-by-reference, you can
even do self.context.manage_addFolder() or whatever, and it will affect
the context originially passed to it.
David
On Mon, 5 Aug 2002, Bo M. Maryniuck wrote:
> Hello, all.
>
> Somebody know how to get a Zope Context within Zope Product or External
> Method?
>
> For example, I have an object (e.g. DTML Method) somewhere in Zope, called as
> "MyObject". It's might be accessed: http://www.myhost.com/test/MyObject
>
> The problem is, that External Method like this works O.K.:
>
> [test.py (External Method)]
> --------8<----------
> def foo(self):
> return self.test.MyObject()
> --------8<----------
>
> ...but *within a class* -- not:
> [test.py (External Method)]
> --------8<----------
> class bar:
> def spam(self):
> return self.test.MyObject()
>
> def foo(self):
> b = bar()
> return b.spam()
> --------8<----------
>
> ...because I need a context, like:
>
> return context.test.MyObject()
>
> ...but I still can't find how to get it. ;-(
> Thank you much.
> --
> Sincerely yours, Bogdan M. Maryniuck
>
> `When you say "I wrote a program that crashed Windows", people just stare at
> you blankly and say "Hey, I got those with the system, *for free*".'
> (By Linus Torvalds)
>
>
> _______________________________________________
> 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 )
>
>