[Zope] Using property() function in Zope 2.8
Max M
maxm at mxm.dk
Thu Jul 6 14:19:36 EDT 2006
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
More information about the Zope
mailing list