[Zope-dev] context bindings in python products

Bernd Dorn bernddorn@hotmail.com
Wed, 6 Jun 2001 12:54:04 +0200


i got it finally - jo

def test(self,REQUEST=None):
        """ test """
        context = REQUEST.PARENTS[0]
        return context.absolute_url()

the reason why:

in another project i used a python script which returns a specific property:
if the property in the current object has some specific value, lets say "--"
then the property is looked up in the parent object (recursively) till it
comes to
a special "root" object.
i use this to let users choose if they want to inherit the property from the
parent object - this is good for meta-tags in html
note that i dont want to let users delete/create properties, and zope only
aquires the
property from the parent if its not there.


now i want to include this function into my python product
so e needed a context object
its not implementet till now, but i think it works with the function above

cu bernd


----- Original Message -----
From: "Toby Dickenson" <tdickenson@devmail.geminidataloggers.co.uk>
To: "Chris McDonough" <chrism@digicool.com>
Cc: "Bernd Dorn" <bernddorn@hotmail.com>; <zope-dev@zope.org>
Sent: Wednesday, June 06, 2001 12:15 PM
Subject: Re: [Zope-dev] context bindings in python products


On Tue, 05 Jun 2001 15:56:45 -0400, Chris McDonough
<chrism@digicool.com> wrote:

>context = self
>container = self.aq_inner.aq_parent

No amount of aquisition trickery will give a method access to the dtml
context, which I *think* is what was asked for.....

>> the only thing i found was this:
>> http://www.zope.org/Members/htrd/howto/FunctionTemplate
>> but it seems very complicated in argument passing

Like DTMLMethods, all arguments get passed in the 'context'.

>> am i the only one who needs this, or is it a sign for wrong coding
practice
>> in zope?

Context-based programming is usually wrong, but not always. If you
explain what you are trying to achieve then we may be able to point
out a better alternative.

(some early drafts of the Zope book encouraged context-based
programing in scenarious where it was quite dangerous; Im not sure if
this is currently true)

Toby Dickenson
tdickenson@geminidataloggers.com

_______________________________________________
Zope-Dev maillist  -  Zope-Dev@zope.org
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists -
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )