[Checkins] SVN: z3c.widget/trunk/src/z3c/widget/optdropdown/ A display widget for the optional choice. I owe the world a test or two.

Stephan Richter srichter at cosmos.phy.tufts.edu
Fri Dec 29 11:23:01 EST 2006


Log message for revision 71676:
  A display widget for the optional choice. I owe the world a test or two.
  

Changed:
  U   z3c.widget/trunk/src/z3c/widget/optdropdown/configure.zcml
  U   z3c.widget/trunk/src/z3c/widget/optdropdown/widget.py

-=-
Modified: z3c.widget/trunk/src/z3c/widget/optdropdown/configure.zcml
===================================================================
--- z3c.widget/trunk/src/z3c/widget/optdropdown/configure.zcml	2006-12-29 15:20:43 UTC (rev 71675)
+++ z3c.widget/trunk/src/z3c/widget/optdropdown/configure.zcml	2006-12-29 16:23:00 UTC (rev 71676)
@@ -4,6 +4,15 @@
 
   <view
       type="zope.publisher.interfaces.browser.IBrowserRequest"
+      for="z3c.schema.optchoice.IOptionalChoice
+           zope.schema.interfaces.IBaseVocabulary"
+      provides="zope.app.form.interfaces.IDisplayWidget"
+      factory=".widget.OptionalDisplayWidget"
+      permission="zope.Public"
+      />
+
+  <view
+      type="zope.publisher.interfaces.browser.IBrowserRequest"
       for="z3c.schema.optchoice.IOptionalChoice"
       provides="zope.app.form.interfaces.IInputWidget"
       factory=".widget.OptionalDropdownWidget"

Modified: z3c.widget/trunk/src/z3c/widget/optdropdown/widget.py
===================================================================
--- z3c.widget/trunk/src/z3c/widget/optdropdown/widget.py	2006-12-29 15:20:43 UTC (rev 71675)
+++ z3c.widget/trunk/src/z3c/widget/optdropdown/widget.py	2006-12-29 16:23:00 UTC (rev 71676)
@@ -20,8 +20,23 @@
 import zope.schema.interfaces
 from zope.app import form
 from zope.app.form import browser
+from zope.app.form.browser.itemswidgets import ItemDisplayWidget
 from zope.app.form.interfaces import MissingInputError
 
+class OptionalDisplayWidget(ItemDisplayWidget):
+
+    def __call__(self):
+        """See IBrowserWidget."""
+        value = self._getFormValue()
+        if not value:
+            return self.translate(self._messageNoValue)
+        elif value not in self.vocabulary:
+            return value
+        else:
+            term = self.vocabulary.getTerm(value)
+            return self.textForValue(term)
+
+
 class OptionalDropdownWidget(object):
     """Optional Dropdown Widget"""
     zope.interface.implements(browser.interfaces.IBrowserWidget,



More information about the Checkins mailing list