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):
  def annotationAdapter(context):
      annotations = IAnnotations(context)
          return annotations[key]
      except KeyError:
          ob = factory()
          annotations[key] = ob
          # to please security...

              ob, context, 'foobar-whatever')
          return ob
  return annotationAdapter

getFoo = makeAnnotationAdapter(IFoo, Foo, FOO_KEY)

Perhaps I'm missing something?!?


This message was sent using IMP, the Internet Messaging Program.
Zope3-dev mailing list

Reply via email to