[Zope-dev] z3c.form pass context to multi widgets in MultiConverter

Roger Ineichen dev at projekt01.ch
Wed Jul 8 07:55:50 EDT 2009


Hi Gerhard

> Betreff: [Zope-dev] z3c.form pass context to multi widgets in 
> MultiConverter
> 
> Hi,
> 
> some widgets may require a valid context to work properly. 
> one such widget is z3c.formquery.
> 
> The attached patch passes the current widget's context to the 
> sub widgets during data conversion in 
> z3c.form.converter.MultiConverter.
> The patch handles this the same way as passing the form 
> property is implemented. (The patch is against current trunk).
> 
> Sorry, but I was not sure how to add a test for this. 
> (However, there is also no explicit test for passing the form 
> property).
> 
> I ran the current test suite with python2.4 and it did not 
> cause any additional issues :) .
> 
> The second patch here was required on my system. It seems, 
> that zope.app.component is a missing dependency for z3c.form. 
> (at least for now).
> 
> cheers,
> 
> Gerhard
> 
> --------------------------------------------------------------
> 
> Index: src/z3c/form/converter.py
> ===================================================================
> --- src/z3c/form/converter.py	(revision 101721)
> +++ src/z3c/form/converter.py	(working copy)
> @@ -359,6 +359,10 @@
>              #form property required by objecwidget
>              widget.form = self.widget.form
>              zope.interface.alsoProvides(widget, 
> interfaces.IFormAware)
> +        if interfaces.IContextAware.providedBy(self.widget):
> +            # context property may be required by objectwidget
> +            widget.context = self.widget.context
> +            zope.interface.alsoProvides(widget, 
> + interface.IContextAware)
>          converter = zope.component.getMultiAdapter((field, widget),
>              interfaces.IDataConverter)
>  
> @@ -377,6 +381,10 @@
>              #form property required by objecwidget
>              widget.form = self.widget.form
>              zope.interface.alsoProvides(widget, 
> interfaces.IFormAware)
> +        if interfaces.IContextAware.providedBy(self.widget):
> +            # context property may be required by objectwidget
> +            widget.context = self.widget.context
> +            zope.interface.alsoProvides(widget, 
> + interface.IContextAware)
>          converter = zope.component.getMultiAdapter((field, widget),
>              interfaces.IDataConverter)

Much thanks for your improvments!

There is a form property called ignoreContext. If this property
is set, the context is ignored explicit. You can set the ignoreContext
property on selected widgets or in a form.

I'm not sure but it looks to me that the ignoreContext property should
also be a part of this patch.

My question,
The following line in the code will set/dispatch the context:
"widget.context = self.widget.context"

Are I'm right, the context of the self.widget.context could be an
ignored context but the widget.context should not ba an ignored
context?

Is this a valid usecase? At least I think this was also not
supported without your patch.

If this makes sense, the patch should probably do soemthing like:

if not widget.ignoreContext
    widget.context = widget.form.context

This whould prevent to set an ignored context from
self.widget.context to the widget.context.


I'm really not sure if this is working, but does this make sense to you?

Regards
Roger Ineichen





More information about the Zope-Dev mailing list