Using property() function in Zope 2.8
I needed to dynamically generate local roles for an Archetypes based content object today. Different layers in my Plone stack breaks all rules and reads the __ac_local_roles__ variable directly, instead of calling get_local_roles() So to maximize the compatibility between Zopes zmi and Plones local roles management I wanted to make '__ac_local_roles__' a property with setters and getters. My AT class was based via a few hops on: 'from ExtensionClass import Base'. And as far as I understand from the release notes Zope 2.8.x should use extension classes based on new style classes. So the property function should work. This code below works in plain Python. But when I add them to my zope class, and run the tester() method I get an "Attributer Error: __ac_local_roles__" Any ideas/comments? # -*- coding: latin-1 -*- class PropTest: def get__ac_local_roles__(self): return self.__mxm__ac_local_roles__ def set__ac_local_roles__(self, value): self.__mxm__ac_local_roles__ = value def del__ac_local_roles__(self): del self.__mxm__ac_local_roles__ __ac_local_roles__ = property(get__ac_local_roles__, set__ac_local_roles__, del__ac_local_roles__, "Local roles on object") def tester(self): return self.__ac_local_roles__ if __name__ == '__main__': p = PropTest() p.__ac_local_roles__ = 'working' print p.tester() -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science Phone: +45 66 11 84 94 Mobile: +45 29 93 42 96
On 7/6/06, Max M <maxm@mxm.dk> wrote:
This code below works in plain Python. But when I add them to my zope class, and run the tester() method I get an "Attributer Error: __ac_local_roles__"
Descriptors in general are not guarantteed to work on old-style classes. Your PropTest class certainly looks like it falls into that category (I'm assuming you didn't elide anything for brevity), so I wouldn't expect it to work. That said, reading such a descriptor will work for classic classes. The real error is getting masked, however: it's not that __ac_local_roles__ isn't defined, it's that __mxm__ac_local_roles__ isn't defined, and the getter isn't dealing with that effectively (or, it is, depending on your opinion). -Fred -- Fred L. Drake, Jr. <fdrake at gmail.com> "Every sin is the result of a collaboration." --Lucius Annaeus Seneca
On Thu, 06 Jul 2006 21:19:36 +0200, Max M wrote:
I needed to dynamically generate local roles for an Archetypes based content object today.
Different layers in my Plone stack breaks all rules and reads the __ac_local_roles__ variable directly, instead of calling get_local_roles()
So to maximize the compatibility between Zopes zmi and Plones local roles management I wanted to make '__ac_local_roles__' a property with setters and getters.
it's not an answer to your original question (i have nothing to add to what fred already replied) but TeamSpace solves this by using a ComputedAttribute instead of a property for the dynamic local roles. all of the pertinent code is here, hope you find it useful: http://svn.plone.org/view/collective/teamspace/tags/1.4/security.py?rev=2460... -r
On 7/6/06, Rob Miller <ra@burningman.com> wrote:
it's not an answer to your original question (i have nothing to add to what fred already replied) but TeamSpace solves this by using a ComputedAttribute instead of a property for the dynamic local roles.
Yeah, I forgot all about ComputedAttribute. That's probably what you want if your class is an ExtensionClass. -Fred -- Fred L. Drake, Jr. <fdrake at gmail.com> "Every sin is the result of a collaboration." --Lucius Annaeus Seneca
Fred Drake wrote:
On 7/6/06, Rob Miller <ra@burningman.com> wrote:
it's not an answer to your original question (i have nothing to add to what fred already replied) but TeamSpace solves this by using a ComputedAttribute instead of a property for the dynamic local roles.
Yeah, I forgot all about ComputedAttribute. That's probably what you want if your class is an ExtensionClass.
Yeah. I remember too now. I don't think I have used one of those since 2000 in plain Zope. Thanks. -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science Phone: +45 66 11 84 94 Mobile: +45 29 93 42 96
participants (3)
-
Fred Drake -
Max M -
Rob Miller