[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form - widget.py:1.30

Fred L. Drake, Jr. fred@zope.com
Mon, 19 May 2003 16:54:04 -0400


Update of /cvs-repository/Zope3/src/zope/app/browser/form
In directory cvs.zope.org:/tmp/cvs-serv13116

Modified Files:
	widget.py 
Log Message:
Various minor cleanups.


=== Zope3/src/zope/app/browser/form/widget.py 1.29 => 1.30 ===
--- Zope3/src/zope/app/browser/form/widget.py:1.29	Wed Apr 30 19:37:51 2003
+++ Zope3/src/zope/app/browser/form/widget.py	Mon May 19 16:54:03 2003
@@ -17,8 +17,6 @@
 
 __metaclass__ = type
 
-from types import ListType, TupleType
-ListTypes = (ListType, TupleType)
 from zope.proxy.introspection import removeAllProxies
 from zope.publisher.browser import BrowserView
 from zope.app.interfaces.browser.form import IBrowserWidget
@@ -30,6 +28,8 @@
 from zope.schema.interfaces import ValidationError
 from zope.component import getService
 
+ListTypes = list, tuple
+
 
 class BrowserWidget(Widget, BrowserView):
     """A field widget that knows how to display itself as HTML."""
@@ -82,17 +82,21 @@
         return value
 
     def _showData(self):
-
-        if (self._data is None):
+        if self._data is None:
             if self.haveData():
                 data = self.getData(1)
             else:
-                data = self.context.default
+                data = self._getDefault()
         else:
             data = self._data
 
         return self._unconvert(data)
 
+    def _getDefault(self):
+        # Return the default value for this widget;
+        # may be overridden by subclasses.
+        return self.context.default
+
     def __call__(self):
         return renderElement(self.getValue('tag'),
                              type = self.getValue('type'),
@@ -111,8 +115,6 @@
                              cssClass = self.getValue('cssClass'),
                              extra = self.getValue('extra'))
 
-
-
     def render(self, value):
         self.setData(value)
         return self()
@@ -333,8 +335,7 @@
     default = ""
     width = 60
     height = 15
-    extra=""
-    #style="width:100%"
+    extra = ""
     style = ''
 
     def _convert(self, value):
@@ -594,7 +595,7 @@
     """A widget with a number of items that has multiple selectable items."""
     default = []
 
-    def _convert(self, value, ListTypes = (list, tuple)):
+    def _convert(self, value):
         if value is None:
             return []
         if isinstance(value, ListTypes):
@@ -717,7 +718,8 @@
     else:
         cssWidgetType = ''
     if cssWidgetType or cssClass:
-        attr_list.append('class="%s"' % ' '.join((cssClass, cssWidgetType)))
+        names = filter(None, (cssClass, cssWidgetType))
+        attr_list.append('class="%s"' % ' '.join(names))
 
     if 'style' in kw:
         if kw['style'] != '':