[z3-five] objects, security,etc
kevin7kal
plone at kevinkal.com
Thu Jul 20 14:53:46 CEST 2006
Maybe opening a tgz is more of a hassle for some. So I will cut and
paste my code and hopefully someone can point out my errror.
I create a 'Zclass2' object through the zmi and try this 'Script(Python)'
MZ = context.Zclass2
#print MZ.attribute1b.method1()
print MZ.attribute1b
print MZ.attribute1a
return printed
if I uncomment line 2, it fails with unauthorized to access attribute
'attribute1b'
--------------configure.zcml----------------------
<configure xmlns="http://namespaces.zope.org/zope"
xmlns:five="http://namespaces.zope.org/five"
xmlns:browser="http://namespaces.zope.org/browser">
<!-- Declare the interfaces -->
<interface interface=".interfaces.Izclass2"
type="zope.app.content.interfaces.IContentType"/>
<!-- Define the permissions -->
<permission id="ZClass2.ManageZClass"
title="Thesaurus: Manage Thesaurus"/>
<!-- Register the classes -->
<five:registerClass class="Products.sampleProduct.myZClass.Zclass2"
meta_type="My Z Class2"
permission="ZClass2.ManageZClass"
addview="zclass2_addform" />
<!-- Content -->
<content class=".myZClass.Zclass2">
<require permission="zope2.View"
interface=".interfaces.Izclass2"/>
</content>
<class class="Products.sampleProduct.myClass.class1">
<require permission="zope2.View" attributes="attribute1 attribute2
method1 method2" />
</class>
<class class="Products.sampleProduct.myClass.class2">
<require permission="zope2.View" attributes="attribute1a attribute2a
method1a method2a" />
</class>
<!-- Browser Views -->
<browser:addform schema=".interfaces.Izclass2"
content_factory=".myZClass.Zclass2"
label="My Z Class2"
name="zclass2_addform"
permission="ZClass2.ManageZClass"/>
<!-- Make Classes Traversable -->
<five:traversable class="OFS.Application.Application"/>
<five:traversable class="OFS.SimpleItem.SimpleItem"/>
<five:traversable class="OFS.Folder.Folder"/>
<five:traversable class="Products.sampleProduct.myZClass"/>
</configure>
-------------------myClass.py-----------------------------------
class class1(object):
''' a simple class with some attributes and methods'''
attribute1 = 'attribute 1'
attribute2 = 'attribute 2'
def __init__(self):
'''simple init for the class'''
return
def method1(self):
'''simple method 1'''
print 'method1'
return
def method2(self):
''' simple method 2'''
print 'method2'
return
class class2(object):
''' a second simple class with some attributes and methods'''
attribute1a = 'attribute 1a'
atrribute2a = 'attribute 2a'
def __init__(self):
'''simple init for the class'''
return
def method1a(self):
'''simple method 1a'''
return(class1)
def method2a(self):
'''simple method 2a'''
return(class1.method1())
attribute1b = property(fget=method1a)
attribute2b = property(fget=method2a)
----------------------myZClass.py-------------------------
from zope.interface import implements
from zope.schema.fieldproperty import FieldProperty
from OFS.SimpleItem import Item, SimpleItem
from persistent import Persistent
import myClass
from interfaces import *
class Zclass2(SimpleItem,myClass.class2):
'''a simple zope class that inherits from my class'''
implements(Izclass2)
def __init__(self,tmpID='',tmpTITLE=''):
'''non empty docstring'''
return
--------------------interfaces.py----------------------------
from zope.interface import Interface
from zope.schema import Text,TextLine
class Izclass1(Interface):
'''marker interface'''
class Izclass2(Interface):
'''marker interface'''
Please-point me to the err in my ways :-)
Thanks!
More information about the z3-five
mailing list