[Zope] Allowing access to Zope Product in Control Panel
kapil thangavelu
kthangavelu@earthlink.net
Mon, 1 Apr 2002 16:23:36 -0800
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')
> 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
ok, this will never work. what you want to import is
from Products.MyProduct.Utils import my_class_attr
ie. your importing directly from the python module not through some object
indirection of the control panel.
> 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
try, from Products.ERAA import Accessor
> Same result. I'm stuck. Any more ideas?
sorry for the misconstrued advice :( , one more note, i had some difficulties
with this under zope2.4.1 because it was over righting the module security
declarations, which created some problems based on order of importing, this
is fixed in 2.5 (and maybe latter 2.4.Xs)
hth,
kapil