[Zope3-dev] Re: a new zcml directive?
Philipp von Weitershausen
philipp at weitershausen.de
Thu Mar 16 00:54:43 EST 2006
Martijn Faassen wrote:
> I stand by my conclusions on this approach sounding simple in theory,
> but still being a bit harder than it should be in practice. :)
I think this is pretty simple:
def makeAnnotationAdapter(for_, factory, key):
@zope.component.adapter(for_)
@zope.interface.implementer(IAnnotations)
def annotationAdapter(context):
annotations = IAnnotations(context)
try:
return annotations[key]
except KeyError:
ob = factory()
annotations[key] = ob
# to please security...
zope.app.container.contained.contained(
ob, context, 'foobar-whatever')
return ob
return annotationAdapter
getFoo = makeAnnotationAdapter(IFoo, Foo, FOO_KEY)
Perhaps I'm missing something?!?
Philipp
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
More information about the Zope3-dev
mailing list