[Zope3-checkins] Re: [Checkins]
SVN:z3c.form/branches/pcardune-tweaks/src/z3c/form/button.pyadded
an adapter hook to allow for customized ButtonActionobjects.
Not sure what the best way to test this is.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Tue Jun 19 16:50:49 EDT 2007
On Tuesday 19 June 2007 16:07, Paul Carduner wrote:
> > > > + # Look up a button action factory
> > > > + buttonAction = zope.component.queryMultiAdapter(
> > > > + (self.request, button, fullName),
> > > > + interfaces.IFieldWidget)
> > > > + # if one is not found, use the default
> > > > + if buttonAction is None:
> > > > + buttonAction = ButtonAction(self.request, button,
> > > > fullName) # Look up a potential custom title for the action.
> > > > title = zope.component.queryMultiAdapter(
> > > > (self.form, self.request, self.content, button,
> > > > self),
> >
> > Including the prefix in the adapter name isn't a good idea.
> > And why not use the form itself as a adapter discriminator.
> > Probably I'm totaly wrong because I didn't take a look at the
> > source code.
> >
> > Regards
> > Roger Ineichen
>
> Why not use the form? Some forms would have a mix of button types
> with different button actions. And you need to include the prefix so
> that the button action gets rendered correctly. Why isn't including
> the prefix a good idea?
Okay, I did not review this code snippet carefully enough. Sigh. The
multi-adapter lookup will not work as intended:
buttonAction = zope.component.queryMultiAdapter(
(self.request, button, fullName), interfaces.IFieldWidget)
This call makes the "fullName" a required object of the adaptation, which is
no good. This adapter lookup should really have the same signature as looking
up any other widget for a field (field.py, line 227):
widget = zope.component.getMultiAdapter(
(field.field, self.request), interfaces.IFieldWidget)
So this should convert to:
buttonAction = zope.component.queryMultiAdapter(
(button, self.request), interfaces.IFieldWidget)
Mmh, reading this lets me think that the form and context should also be part
of the required objects (as Roger hinted at). Maybe we can do this later.
As for your concerns, Paul, the button provides enough specificity that no
name discriminataion is needed. Remember, buttons are just fields and we can
register actions/widgets on field *instances*!
Regards,
Stephan
--
Stephan Richter
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training
More information about the Zope3-Checkins
mailing list