[Product-Developers] Re: @property strips acquisition context

Martin Aspeli optilude+lists at gmail.com
Tue Sep 1 00:54:24 UTC 2009

Hedley Roos wrote:
> Replying to my own post for future reference...
> I was not successful in using @ComputedAttribute, but I could do
> def _foo(self):
>   # Trivial example
>   return self.aq_parent.id
> foo = ComputedAttribute(_foo, 1)
> This looks a lot like the way we used to do decorators before we got
> the @ syntactic sugar. Maybe the correct way to use the decorator is
> @ComputedAttribute(1). I don't know and I do not have enough time to
> investigate.

I think you'd need to make a custom decorator. Something like:

def aq_aware_property(fn):
     return ComputedAttribute(fn, 1)

Then you can do:

def foo(self):
     return self.aq_parent.id


Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book

More information about the Product-Developers mailing list