[Zope] Allowing access to Zope Product in Control Panel
Itai Tavor
itai@optusnet.com.au
Mon, 1 Apr 2002 10:29:29 +1000
>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.
in Utils.py:
from Products.PythonScripts.Utility import allow_module
allow_module('MyProduct.Utils')
allow_module('Products.MyProduct.Utils')
allow_module('Control_Panel.Products.MyProduct.Utils')
(I tried each one of the above 3)
def myclass_attr_access(name):
return getattr(MyClass, name, None)
in Python Script:
from context.Control_Panel.Products.MyProduct.Utils import myclass_attr_access
Result:
import of "context.Control_Panel.Products.ERAA.Utils" is unauthorized
I also tried:
in __init__.py:
class Accessor:
def myclass_attr_access(name):
return getattr(MyClass, name, None)
allow_class(Accessor)
in Python Script:
from context.Control_Panel.Products.ERAA import Accessor
Same result. I'm stuck. Any more ideas?
TIA, Itai
--
--
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" --