[Zope] ANNOUNCE: An easier way to write products
maxm
maxm@mxm.dk
Thu, 10 Jan 2002 13:42:38 +0100
From: "Oleg Broytmann" <phd@phd.pp.ru>
> Ever looked to Zope beans?
> http://www.pault.com/pault/zope/zope_beans.html
Yes, but I think my approach is more in line with Zope. To me it is anyway.
Also I need a new object format like a hole in the the head ;-) Here I am
thinking of the xml format describing the Zope bean.
But see below. I don't tink that the "easy" approach is harder than the
"bean" approach. They are both about the same amount of lines anyway :-)
And how do you set Security on the methods?
And if you change the "_properties" in the "easy" approach they are
immediately updated in your product.
regards Max M
#####################################################
#####################################################
<bean>
<name> Hello </name>
<icon> bean.gif </icon>
<version> 0-0-1 </version>
<meta> Sample Zope Bean </meta>
<property name="greeting" type="string">
Default Greeting
</property>
<property name="counter" type="string">3</property>
<method name="SayGreeting" />
<method name="SaySomething"/>
<readme>
Hello Zope Bean.
This is sample bean to show how Zope Beans work.
</readme>
</bean>
#####################################################
class Hello:
"Actual semantics of Hello Bean"
def SayGreeting(self):
return "Greeting is: " + self.get_greeting()
def SaySomething(self, msg, ntimes ):
ret = []
for n in range( 1,ntimes ) :
ret.append(
self.get_greeting() +
" By the way ... " + msg)
return ret
#####################################################
#####################################################
from mxm import mxmSimpleItem
class Hello(mxmSimpleItem.mxmSimpleItem):
meta_type = 'Hello'
_properties = (
{'id':greeting, 'type':'string', 'mode':'w'},
{'id':counter, 'type':'text', 'mode':'w'},
)
__ac_permissions__ = mxmSimpleItem.__ac_permissions__ + (
# label
('View',
# methods
('SayGreeting','SaySomething'),
# roles
('Anonymous', 'Manager'),
),
)
def SayGreeting(self):
""
return "Greeting is: " + self.greeting
def SaySomething(self, msg, ntimes ):
""
ret = []
for n in range( 1,ntimes ) :
ret.append(
self.greeting +
" By the way ... " + msg)
return ret
def manage_addAction(self, id=None, REQUEST=None):
"Add instance to parent ObjectManager"
mxmSimpleItem.addClass(self, id, Hello, REQUEST)
constructors = (mxmSimpleItem.manage_addForm, manage_addAction)
#####################################################
import mxmItem
def initialize(context):
context.registerClass(
mxmItem.mxmItem,
constructors = mxmItem.constructors,
icon="bean.gif"
)
#####################################################