[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/form/browser/ Checked in a configuration fix. SourceListInputWidget was registered

Jim Fulton jim at zope.com
Fri Feb 11 16:40:28 EST 2005


Log message for revision 29122:
  Checked in a configuration fix.  SourceListInputWidget was registered
  for zope.schema.interfaces.ISequence, but it was only applicable to 
  IList. We need an ITuple version.  Included an XXX along these lines.
  
  Also added a source sequence display widget.  I'm in debt. :(
  I need to write a test for it.  I also need to write the missing
  tests for the source display and the source list input. :(
  
  Waaa.
  

Changed:
  U   Zope3/trunk/src/zope/app/form/browser/configure.zcml
  U   Zope3/trunk/src/zope/app/form/browser/source.py

-=-
Modified: Zope3/trunk/src/zope/app/form/browser/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/configure.zcml	2005-02-11 20:32:49 UTC (rev 29121)
+++ Zope3/trunk/src/zope/app/form/browser/configure.zcml	2005-02-11 21:40:28 UTC (rev 29122)
@@ -398,11 +398,21 @@
       permission="zope.Public"
       />
 
+  <view
+      type="zope.publisher.interfaces.browser.IBrowserRequest"
+      for="zope.schema.interfaces.ISequence
+           zope.schema.interfaces.ISource"
+      provides="zope.app.form.interfaces.IDisplayWidget"
+      factory=".source.SourceSequenceDisplayWidget"
+      permission="zope.Public"
+      />
+
+
   <!-- XXX The configuration below should be for IList -->
   <!--     We need a widget for tuples (and sets, for that matter). -->
   <view
       type="zope.publisher.interfaces.browser.IBrowserRequest"
-      for="zope.schema.interfaces.ISequence
+      for="zope.schema.interfaces.IList
            zope.schema.interfaces.ISource"
       provides="zope.app.form.interfaces.IInputWidget"
       factory=".source.SourceListInputWidget"

Modified: Zope3/trunk/src/zope/app/form/browser/source.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/source.py	2005-02-11 20:32:49 UTC (rev 29121)
+++ Zope3/trunk/src/zope/app/form/browser/source.py	2005-02-11 21:40:28 UTC (rev 29122)
@@ -66,6 +66,34 @@
 
         return value
 
+class SourceSequenceDisplayWidget(SourceDisplayWidget):
+
+    def __call__(self):
+
+        if self._renderedValueSet():
+            seq = self._data
+        else:
+            seq = self.context.default
+
+        terms = zapi.getMultiAdapter(
+            (self.source, self.request),
+            zope.app.form.browser.interfaces.ITerms,
+            )
+        result = []
+        for value in seq:
+            try:
+                term = terms.getTerm(value)
+            except LookupError:
+                value = self._translate(_("SourceDisplayWidget-invalid",
+                                          default="Invalid value"))
+            else:
+                value = cgi.escape(term.title)
+
+            result.append(value)
+
+        return '<br />\n'.join(result)
+    
+
 class SourceInputWidget(zope.app.form.InputWidget):
 
     _error = None



More information about the Zope3-Checkins mailing list