[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/form/browser/ provide a more specific display widget for IBytes (but not IBytesLine) fields

Fred L. Drake, Jr. fdrake at gmail.com
Wed Nov 3 13:40:19 EST 2004


Log message for revision 28333:
  provide a more specific display widget for IBytes (but not IBytesLine) fields

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

-=-
Modified: Zope3/trunk/src/zope/app/form/browser/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/__init__.py	2004-11-03 18:12:32 UTC (rev 28332)
+++ Zope3/trunk/src/zope/app/form/browser/__init__.py	2004-11-03 18:40:18 UTC (rev 28333)
@@ -25,6 +25,7 @@
 from zope.app.form.browser.textwidgets import ASCIIWidget
 from zope.app.form.browser.textwidgets import IntWidget, FloatWidget
 from zope.app.form.browser.textwidgets import DatetimeWidget, DateWidget
+from zope.app.form.browser.textwidgets import BytesDisplayWidget
 
 # Widgets for boolean fields
 from zope.app.form.browser.boolwidgets import CheckBoxWidget

Modified: Zope3/trunk/src/zope/app/form/browser/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/configure.zcml	2004-11-03 18:12:32 UTC (rev 28332)
+++ Zope3/trunk/src/zope/app/form/browser/configure.zcml	2004-11-03 18:40:18 UTC (rev 28333)
@@ -54,6 +54,22 @@
       permission="zope.Public"
       />
 
+  <view
+      type="zope.publisher.interfaces.browser.IBrowserRequest"
+      for="zope.schema.interfaces.IBytes"
+      provides="zope.app.form.interfaces.IDisplayWidget"
+      factory=".textwidgets.BytesDisplayWidget"
+      permission="zope.Public"
+      />
+
+  <view
+      type="zope.publisher.interfaces.browser.IBrowserRequest"
+      for="zope.schema.interfaces.IBytesLine"
+      provides="zope.app.form.interfaces.IDisplayWidget"
+      factory=".DisplayWidget"
+      permission="zope.Public"
+      />
+
   <!-- Core edit widgets -->
 
   <view

Modified: Zope3/trunk/src/zope/app/form/browser/textwidgets.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/textwidgets.py	2004-11-03 18:12:32 UTC (rev 28332)
+++ Zope3/trunk/src/zope/app/form/browser/textwidgets.py	2004-11-03 18:40:18 UTC (rev 28333)
@@ -23,6 +23,7 @@
 from zope.app.form.interfaces import IInputWidget, ConversionError
 from zope.app.form.browser.interfaces import ITextBrowserWidget
 from zope.app.form.browser.widget import SimpleInputWidget, renderElement
+from zope.app.form.browser.widget import DisplayWidget
 from zope.app.datetimeutils import parseDatetimetz
 from zope.app.datetimeutils import DateTimeError
 
@@ -186,6 +187,16 @@
     'Bob'
     """
 
+class BytesDisplayWidget(DisplayWidget):
+    """Bytes display widget"""
+
+    def __call__(self):
+        if self._renderedValueSet():
+            content = self._data
+        else:
+            content = self.context.default
+        return renderElement("pre", contents=escape(content))
+
 class ASCII(Bytes):
     """ASCII"""
 



More information about the Zope3-Checkins mailing list