[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/Forms/Views/Browser - Widget.py:1.14 configure.zcml:1.11
Jim Fulton
jim@zope.com
Wed, 11 Dec 2002 08:52:48 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Forms/Views/Browser
In directory cvs.zope.org:/tmp/cvs-serv10602
Modified Files:
Widget.py configure.zcml
Log Message:
Added a default display widget for most fields. Some fields will need to customize this
=== Zope3/lib/python/Zope/App/Forms/Views/Browser/Widget.py 1.13 => 1.14 ===
--- Zope3/lib/python/Zope/App/Forms/Views/Browser/Widget.py:1.13 Thu Dec 5 08:27:04 2002
+++ Zope3/lib/python/Zope/App/Forms/Views/Browser/Widget.py Wed Dec 11 08:52:48 2002
@@ -46,13 +46,13 @@
def haveData(self):
return (self.name) in self.request.form
- def getData(self):
+ def getData(self, optional=0):
field = self.context
value = self.request.form.get(self.name,
self)
if value is self:
# No user input
- if field.required:
+ if field.required and not optional:
raise MissingInputError(field.__name__)
return field.default
@@ -66,10 +66,13 @@
exc = ConversionError(sys.exc_info()[1])
raise ConversionError, exc, sys.exc_info()[2]
- try:
- field.validate(value)
- except ValidationError, v:
- raise WidgetInputError(self.context.__name__, self.title, str(v))
+ if value is not None or not optional:
+
+ try:
+ field.validate(value)
+ except ValidationError, v:
+ raise WidgetInputError(self.context.__name__,
+ self.title, str(v))
return value
@@ -85,7 +88,7 @@
def _showData(self):
if (self._data is None) and self.haveData():
- data = self.getData()
+ data = self.getData(1)
else:
data = self._data
@@ -131,6 +134,11 @@
def row(self):
return "<td>%s</td><td>%s</td>" % (self.label(), self())
+
+class DisplayWidget(BrowserWidget):
+
+ def __call__(self):
+ return self._showData()
class CheckBoxWidget(BrowserWidget):
"""Checkbox widget"""
=== Zope3/lib/python/Zope/App/Forms/Views/Browser/configure.zcml 1.10 => 1.11 ===
--- Zope3/lib/python/Zope/App/Forms/Views/Browser/configure.zcml:1.10 Mon Dec 9 11:09:18 2002
+++ Zope3/lib/python/Zope/App/Forms/Views/Browser/configure.zcml Wed Dec 11 08:52:48 2002
@@ -70,5 +70,12 @@
name="edit"
factory=".Widget.TextAreaWidget." />
+ <!-- Default simple display view -->
+ <browser:view
+ permission="Zope.Public"
+ allowed_interface=".IBrowserWidget."
+ for="Zope.Schema.IField.IField"
+ name="display"
+ factory=".Widget.DisplayWidget" />
</zopeConfigure>