[Zope3-dev] SourceInputWidget

Marc Rijken marc at rijken.org
Wed Aug 3 16:46:30 EDT 2005


Hi all,

I want to propose two little changes to SourceInputWidget 
(zope.app.form.browser.source).

1. Context in Source

At this moment, it is not possible to use the context in the source,
because they do not get the context from the SourceInputWidget. For a
typical source, I need the context, so I can lookup terms that are
valid only in a specific context. I propose the following change, because the 
context is in the field which is passed to the constructor:

     def __init__(self, field, source, request):
         super(SourceInputWidget, self).__init__(field, request)
         self.source = source

         # changed in order to let the source know the fieldcontext
         self.source.field = field
         # end of changes

         <snip>


2. use _toFieldValue en _toFormValue in SourceInputWidget.

_toFieldValue and _toFormValue are powerfull functions in widgets to use a) a
standard widget and b) override the widget on specific parts. I need a
SourceInputWidget which uses an instance of a class as value. Because
the SourceInputWidget only works with strings, I had to convert the
string to/from the class instance. The _toFieldValue and _toFormValue
are very usefull for that purpose, so I propose the following change:

     def _value(self):
         if self._renderedValueSet():
             value = self._data
             #changed in order to let the value change
             value = self._toFormValue(value)
             #end changes

             <snip>


     def getInputValue(self):
         <snip>

         try:
             value = self.terms.getValue(str(token))
             #changed in order to let the value change
             value = self._toFieldValue(value)
             #end changes

         <snip>


Are there any objections to these proposed changes? I'am not a Zope3
Developer, so is anyone willing to make these changes in Zope3?

Thanx,

Marc


More information about the Zope3-dev mailing list