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

Steve Alexander steve@cat-box.net
Thu, 20 Feb 2003 11:46:37 -0500


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

Modified Files:
	widget.py 
Log Message:
Removed allowed_values=[(value,text),...] convention from widget.py --
it shouldn't have been there in the first place :)

Removed some unwanted whitespace, and flagged a bunch of opaque code
and bare except:s with XXX comments.


=== Zope3/src/zope/app/browser/form/widget.py 1.16 => 1.17 ===
--- Zope3/src/zope/app/browser/form/widget.py:1.16	Thu Feb 20 10:36:34 2003
+++ Zope3/src/zope/app/browser/form/widget.py	Thu Feb 20 11:46:05 2003
@@ -427,7 +427,13 @@
     """A widget with a number of items that has only a single
     selectable item."""
     default = ""
-    firstItem = 0
+    firstItem = False
+
+    def textForValue(self, value):
+        '''Returns the text for the given value.
+
+        Override this in subclasses.'''
+        return value
 
     def renderItems(self, value):
         name = self.name
@@ -435,24 +441,17 @@
         items = self.context.allowed_values
 
         # check if we want to select first item
-        if (not value and getattr(self.context, 'firstItem', None)
+        if (not value and getattr(self.context, 'firstItem', False)
             and len(items) > 0):
-            try:
-                text, value = items[0]
-            except ValueError:
-                value = items[0]
+            value = items[0]
 
         cssClass = self.getValue('cssClass')
 
         # FIXME: what if we run into multiple items with same value?
         rendered_items = []
         count = 0
-        for item in items:
-            try:
-                item_value, item_text = item
-            except ValueError:
-                item_value = item
-                item_text = item
+        for item_value in items:
+            item_text = self.textForValue(item_value)
 
             if item_value == value:
                 rendered_item = self.renderSelectedItem(count,