[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/form/browser/ add a working display widget for boolean fields

Fred L. Drake, Jr. fdrake at gmail.com
Fri Oct 8 15:23:58 EDT 2004


Log message for revision 27794:
  add a working display widget for boolean fields


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


-=-
Modified: Zope3/trunk/src/zope/app/form/browser/boolwidgets.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/boolwidgets.py	2004-10-08 09:39:47 UTC (rev 27793)
+++ Zope3/trunk/src/zope/app/form/browser/boolwidgets.py	2004-10-08 19:23:57 UTC (rev 27794)
@@ -21,6 +21,7 @@
 from zope.schema.vocabulary import SimpleVocabulary
 
 from zope.app.form.browser.widget import SimpleInputWidget, renderElement
+from zope.app.form.browser.widget import DisplayWidget
 from zope.app.form.browser.itemswidgets import RadioWidget
 from zope.app.form.browser.itemswidgets import SelectWidget, DropdownWidget
 from zope.app.form.interfaces import IInputWidget
@@ -105,3 +106,19 @@
 def BooleanDropdownWidget(field, request, true=_('on'), false=_('off')):
     vocabulary = SimpleVocabulary.fromItems( ((true, True), (false, False)) )
     return DropdownWidget(field, vocabulary, request)
+
+
+_msg_true = _("True")
+_msg_false = _("False")
+
+class BooleanDisplayWidget(DisplayWidget):
+
+    def __call__(self):
+        if self._renderedValueSet():
+            value = self._data
+        else:
+            value = self.context.default
+        if value:
+            return _msg_true
+        else:
+            return _msg_false

Modified: Zope3/trunk/src/zope/app/form/browser/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/configure.zcml	2004-10-08 09:39:47 UTC (rev 27793)
+++ Zope3/trunk/src/zope/app/form/browser/configure.zcml	2004-10-08 19:23:57 UTC (rev 27794)
@@ -46,6 +46,14 @@
       permission="zope.Public"
       />
 
+  <view
+      type="zope.publisher.interfaces.browser.IBrowserRequest"
+      for="zope.schema.interfaces.IBool"
+      provides="zope.app.form.interfaces.IDisplayWidget"
+      factory=".boolwidgets.BooleanDisplayWidget"
+      permission="zope.Public"
+      />
+
   <!-- Core edit widgets -->
 
   <view



More information about the Zope3-Checkins mailing list