[Zope-dev] z3c.form pass context to multi widgets in MultiConverter
Gerhard Weis
gweis at gmx.at
Tue Jul 7 23:23:02 EDT 2009
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)
------------------------------------------------------------------------
Index: setup.py
===================================================================
--- setup.py (revision 101721)
+++ setup.py (working copy)
@@ -84,6 +84,7 @@
'z3c.coverage',
'z3c.template',
'zc.sourcefactory',
+ 'zope.app.component',
'zope.app.container',
'zope.app.i18n',
'zope.app.pagetemplate',
More information about the Zope-Dev
mailing list