[Zope3-dev] Re: Field binding considered icky
Garrett Smith
garrett at mojave-corp.com
Wed Mar 31 20:46:08 EST 2004
Jim Fulton wrote:
> I'm trying to catch up a bit on documentation. I'm working on
> README.txt files for zope.interface and zope.component and will be
> updating the README.txt for zope.schema.
>
> There is a "feature" of schema fields that I really don't want to
> document. This feature is called "binding". A field can be "bound"
> to an object. This creates a new field instance, which is a clone of
> the original, that has a `context` attribute which is some object.
> The object *may*, for example, be an object that has an attribute that
> is specified by the field.
Apart from being hackish (er...icky?), why does the current approach
need to be revamped?
> We would get rid of the validate method of fields.
>
> When we want to validate a field, we'll adapt it *with* it's
> context:
>
> >>> validator = getMultiAdapter((field, context), IValidator)
> >>> validator.validate(value)
>
> A disadvantage of this approach is that it will require either
> that:
>
> - We remove validation logic from zope.schema, or
This doesn't seem like a disadvantage.
> - Introduce a dependency of zope.schema on zope.component. Later,
> if we merge zope.schema into zope.interface, we'd introduce a
> dependency of zope.interface on zope.component.
This definitely seems like a distadvantage.
> B. Widgets
>
> Widgets would become multi-views:
>
> >>> widget = getMultiView((field, context), '', request, IInputWidget)
This makes sense.
> B'. Rather than using multi-views, use views of multi-adapters:
>
> >>> widget = getViewProviding(
> ... getMultiAdapter((field, context), someinterface),
> ... request, IInputWidget,
> ... )
>
> The idea is that the widget need not know about context. Any knowledge
> of the context is restricted to the adapter. I think that this
> has some appeal, but I don't know that I want to require it.
This is getting a bit crazy :-)
> I don't like this option
Same here.
> Thoughts?
In the current implementation, we get to context as an attribute of the
bound field. Is the primary motivation for using multiadapters and
multiviews to avoid the field cloning?
-- Garrett
More information about the Zope3-dev
mailing list