[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/form/browser/ - deal
with missing values a bit better for display forms
Fred L. Drake, Jr.
fdrake at gmail.com
Tue Jan 18 18:13:29 EST 2005
Log message for revision 28868:
- deal with missing values a bit better for display forms
- make sure UnicodeDisplayWidget goes through as much testing as
DisplayWidget
Changed:
U Zope3/trunk/src/zope/app/form/browser/tests/test_displaywidget.py
U Zope3/trunk/src/zope/app/form/browser/widget.py
-=-
Modified: Zope3/trunk/src/zope/app/form/browser/tests/test_displaywidget.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/tests/test_displaywidget.py 2005-01-18 22:45:41 UTC (rev 28867)
+++ Zope3/trunk/src/zope/app/form/browser/tests/test_displaywidget.py 2005-01-18 23:13:28 UTC (rev 28868)
@@ -22,7 +22,7 @@
from zope.schema import TextLine
from zope.testing.doctestunit import DocTestSuite
-from zope.app.form.browser.widget import DisplayWidget
+from zope.app.form.browser.widget import DisplayWidget, UnicodeDisplayWidget
def test_implemented_interfaces():
@@ -86,13 +86,31 @@
>>> widget()
''
-
+
+ If there's no default for the field and the value is missing on
+ the bound object, the empty string should still be displayed::
+
+ >>> field = TextLine(title=u'Title',
+ ... __name__=u'title',
+ ... required=False)
+
+ >>> class Thing:
+ ... title = field.missing_value
+
+ >>> field = field.bind(Thing())
+ >>> widget = DisplayWidget(field, TestRequest())
+
+ >>> widget()
+ ''
+
"""
def test_suite():
suite = unittest.TestSuite()
suite.addTest(DocTestSuite())
+ suite.addTest(DocTestSuite(
+ extraglobs={"DisplayWidget": UnicodeDisplayWidget}))
return suite
if __name__ == '__main__':
Modified: Zope3/trunk/src/zope/app/form/browser/widget.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/widget.py 2005-01-18 22:45:41 UTC (rev 28867)
+++ Zope3/trunk/src/zope/app/form/browser/widget.py 2005-01-18 23:13:28 UTC (rev 28868)
@@ -394,11 +394,12 @@
def __call__(self):
if self._renderedValueSet():
- if self._data == self.context.missing_value:
- return ""
- return escape(self._data)
+ value = self._data
else:
- return escape(self.context.default)
+ value = self.context.default
+ if value == self.context.missing_value:
+ return ""
+ return escape(value)
class UnicodeDisplayWidget(BrowserWidget):
@@ -406,11 +407,12 @@
def __call__(self):
if self._renderedValueSet():
- if self._data == self.context.missing_value:
- return ""
- return escape(unicode(self._data))
+ value = self._data
else:
- return escape(unicode(self.context.default))
+ value = self.context.default
+ if value == self.context.missing_value:
+ return ""
+ return escape(unicode(value))
def renderTag(tag, **kw):
More information about the Zope3-Checkins
mailing list