[Zope-CMF] [dev] using newstyle content factories - a proposal
yuppie
y.2006_ at wcm-solutions.de
Fri May 26 04:41:38 EDT 2006
Hi!
In Zope there are two ways to register content classes and factories:
Oldstyle::
class Foo:
meta_type = 'Foo Type'
def manage_addFoo(folder, id):
ob = Foo(id)
folder._setObject(id, ob)
context.registerClass(
Foo,
constructors=('manage_addFoo',),
permission=AddFoo,
)
Newstyle::
class Foo:
# the meta_type attribute is added by registerClass
FooFactory = Factory(Foo)
<five:registerClass
class=".Foo"
meta_type="Foo Type"
permission="fooproduct.AddFoo"
/>
<factory
component=".FooFactory"
id="fooproduct.foo"
/>
Oldstyle factories are used this way::
dispatcher = folder.manage_addProduct['FooProduct']
dispatcher.manage_addFoo('foo')
And newstyle factories like this::
factory = getUtility(IFactory, 'fooproduct.foo')
ob = factory(id)
folder._setObject(id, obj)
FactoryTypeInformation currently just supports oldstyle factories.
Proposal
========
If the 'product' property of a type info instance is empty the 'factory'
property is interpreted as a newstyle factory ID.
Risks
=====
Newstyle factories are placeless, they know nothing about the container
and can't add the objects themselves to the container. There are many
complex factories out there that can't be easily replaced by newstyle
factories. So we can't deprecate the old way - at least for now.
Any feedback is welcome. If there are no objections I'll check in the
proposed change on the trunk.
Cheers,
Yuppie
More information about the Zope-CMF
mailing list