[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/form/browser/ add a
display widget that converts the value to text before display; this
Fred L. Drake, Jr.
fdrake at gmail.com
Tue Jan 18 17:24:29 EST 2005
Log message for revision 28864:
add a display widget that converts the value to text before display; this
can be used for simple non-text types, such as int and float 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/widget.py
-=-
Modified: Zope3/trunk/src/zope/app/form/browser/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/__init__.py 2005-01-18 19:59:26 UTC (rev 28863)
+++ Zope3/trunk/src/zope/app/form/browser/__init__.py 2005-01-18 22:24:27 UTC (rev 28864)
@@ -18,6 +18,7 @@
__docformat__ = 'restructuredtext'
from zope.app.form.browser.widget import BrowserWidget, DisplayWidget
+from zope.app.form.browser.widget import UnicodeDisplayWidget
from zope.app.form.browser.textwidgets import TextWidget, BytesWidget
from zope.app.form.browser.textwidgets import TextAreaWidget, BytesAreaWidget
Modified: Zope3/trunk/src/zope/app/form/browser/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/configure.zcml 2005-01-18 19:59:26 UTC (rev 28863)
+++ Zope3/trunk/src/zope/app/form/browser/configure.zcml 2005-01-18 22:24:27 UTC (rev 28864)
@@ -154,6 +154,14 @@
<view
type="zope.publisher.interfaces.browser.IBrowserRequest"
+ for="zope.schema.interfaces.IInt"
+ provides="zope.app.form.interfaces.IDisplayWidget"
+ factory=".UnicodeDisplayWidget"
+ permission="zope.Public"
+ />
+
+ <view
+ type="zope.publisher.interfaces.browser.IBrowserRequest"
for="zope.schema.interfaces.IFloat"
provides="zope.app.form.interfaces.IInputWidget"
factory=".FloatWidget"
@@ -162,6 +170,14 @@
<view
type="zope.publisher.interfaces.browser.IBrowserRequest"
+ for="zope.schema.interfaces.IFloat"
+ provides="zope.app.form.interfaces.IDisplayWidget"
+ factory=".UnicodeDisplayWidget"
+ permission="zope.Public"
+ />
+
+ <view
+ type="zope.publisher.interfaces.browser.IBrowserRequest"
for="zope.schema.interfaces.IDatetime"
provides="zope.app.form.interfaces.IInputWidget"
factory=".DatetimeWidget"
Modified: Zope3/trunk/src/zope/app/form/browser/widget.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/widget.py 2005-01-18 19:59:26 UTC (rev 28863)
+++ Zope3/trunk/src/zope/app/form/browser/widget.py 2005-01-18 22:24:27 UTC (rev 28864)
@@ -401,6 +401,18 @@
return escape(self.context.default)
+class UnicodeDisplayWidget(BrowserWidget):
+ """Display widget that converts the value to unicode before display."""
+
+ def __call__(self):
+ if self._renderedValueSet():
+ if self._data == self.context.missing_value:
+ return ""
+ return escape(unicode(self._data))
+ else:
+ return escape(unicode(self.context.default))
+
+
def renderTag(tag, **kw):
"""Render the tag. Well, not all of it, as we may want to / it."""
attr_list = []
More information about the Zope3-Checkins
mailing list