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

2009-07-08 Thread Roger Ineichen
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



___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


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

2009-07-08 Thread Gerhard Weis
Hi Roger,

Roger Ineichen wrote:
 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



   
Thanks for the comment. For this particular use case it won't work 
without the context,. The context is used to look up further objects in 
the containment hierarchy. At this particular part in the code it is 
just about converting from/to widget/field value. So 
ignoreContext/ignoreRequest are not used anyway. (at least not to 
retrieve widget values).

However, maybe it would be better to pass ignoreContex and ignoreRequest 
to the sub-widget, and let the sub-widget decide whether to ignore the 
context/request or not. This could especially be useful in other parts 
of the muti-widget code.

Regards,
Gerhard
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


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

2009-07-08 Thread Roger Ineichen
Hi Gerhard

 Betreff: Re: AW: [Zope-dev] z3c.form pass context to multi 
 widgets in MultiConverter

[...]

  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
 
 
 

 Thanks for the comment. For this particular use case it won't 
 work without the context,. The context is used to look up 
 further objects in the containment hierarchy. At this 
 particular part in the code it is just about converting 
 from/to widget/field value. So ignoreContext/ignoreRequest 
 are not used anyway. (at least not to retrieve widget values).
 
 However, maybe it would be better to pass ignoreContex and 
 ignoreRequest to the sub-widget, and let the sub-widget 
 decide whether to ignore the context/request or not. This 
 could especially be useful in other parts of the muti-widget code.

Yes good idea, this makes sense to me. Can you commit this to the
trunk with a test?

Regards
Roger Ineichen
_
END OF MESSAGE

___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


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

2009-07-08 Thread Gerhard Weis
Hi Roger,

Roger Ineichen wrote:
 I'm really not sure if this is working, but does this make 
   
 sense to you?
 
 Regards
 Roger Ineichen



   
   
 Thanks for the comment. For this particular use case it won't 
 work without the context,. The context is used to look up 
 further objects in the containment hierarchy. At this 
 particular part in the code it is just about converting 
 from/to widget/field value. So ignoreContext/ignoreRequest 
 are not used anyway. (at least not to retrieve widget values).

 However, maybe it would be better to pass ignoreContex and 
 ignoreRequest to the sub-widget, and let the sub-widget 
 decide whether to ignore the context/request or not. This 
 could especially be useful in other parts of the muti-widget code.
 

 Yes good idea, this makes sense to me. Can you commit this to the
 trunk with a test?

   
No sorry, I don't have commit access. I probably can implement the stuff 
mentioned above, and I can try to figure out a test case.
At the end I can send a few patches :).

Regards,

Gerhard


 Regards
 Roger Ineichen
 _
 END OF MESSAGE

   

___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


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

2009-07-07 Thread Gerhard Weis
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',

___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )