On Sunday 31 March 2002 04:29 pm, Itai Tavor wrote:
On Thursday 28 March 2002 08:02 pm, Itai Tavor wrote:
Hi,
I have a python Product MyProduct, defining a class MyClass. I want to be able to do two things with this class from a Python Script:
- Access a property defined in the class without creating an instance of the class
class MyClass(SimpleItem): menu = ('a', 'b', 'c')
In Python Script: menu = context.Control_Panel.MyProduct.MyClass.MyClass.menu
- Create an instance of MyClass without doing registerClass on it.
The question is, how do I create the right permissions so the above can be done? I tried playing with the various methods detailed in PythonScripts/module_access_examples.py but didn't get anywhere.
i would do the above with some accessor functions in a Utility module of the product and then use PythonScripts Modules allow access utility for example.
#Utils.py from Products.PythonScripts.Utility import allow_module from MyModule import MyClass
allow_module('MyProduct.Utils')
def myclass_factory(*args): return MyClass(*args)
def myclass_attr_access(name): return getattr(MyClass, name, None)
in a python script
from MyProducts.Utils import myclass_attr_access
etc...
-kapil
Thanks, Kapil... good suggestion. Sadly, I'm still not getting anywhere... I tried every combination of modules, classes, methods and allow_class/allow_module I could think of, and nothing works.
hi ita,
first there is one mistake in the above i sent previously
the allow_module call should have been
allow_module('Products.MyProduct.Utils')
Kapil, that's it! I tried all the different combinations I could think of, except for this one. Thanks for sticking with me :-)
in Python Script:
from context.Control_Panel.Products.MyProduct.Utils import myclass_attr_access
ok, this will never work. what you want to import is
from Products.MyProduct.Utils import my_class_attr
Yeah, I figured that on my own, I only tried it this way because "from Products..." didn't work. -- -- Itai Tavor -- "Je sautille, donc je suis." -- itai@optusnet.com.au -- - Kermit the Frog -- -- -- -- "If you haven't got your health, you haven't got anything" --