[Zope3-Users] formlib handling of adapters

Marius Gedminas mgedmin at b4net.lt
Sat May 5 14:02:30 EDT 2007

On Sat, May 05, 2007 at 02:07:58PM +0200, Dominique Lederer wrote:
> i just tried to adapt an object with two similar interfaces:
> class IBaseAdapter(Interface):
> 	content = Text(title=u"Content", required=False)
> class IHomeAdapter(IBaseAdapter):
>     """ """
> class ILinksAdapter(IBaseAdapter):
>     """ """
> after that, i created two formlib editform views and registered them on my
> adapted object. The "content" property is saved on different annotation keys on
> the adapted object. The form renders correctly, but the "content" property is
> only handled via the ILinksAdapter by formlib. so content is saved always on the
> same annotation key.
> if i change my interfaces to
> class IHomeAdapter(Interface):
>     content = Text(title=u"Content", required=False)
> class ILinksAdapter(Interface):
>     content = Text(title=u"Content", required=False)
> formlib works and uses the two different adapters implementations.
> looks like a bug, can somebody confirm or comment this?

In your first example the same form field is shared by the three
interfaces (through inheritance).  The field itself knows that it is
part of IBaseAdapter, so formlib tries to adapt your content object to
IBaseAdapter in both cases (and zope.component gives it the
IHomeAdapter, because that's the first one that satisfies the
IBaseAdapter requirement).

I don't know if this is a bug, or if it's supposed to be that way.
It would be very hard to change the behaviour, I expect.

Marius Gedminas
Funny off-topic messages are always on-topic.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zope3-users/attachments/20070505/ff27395c/attachment.bin

More information about the Zope3-users mailing list