[Zope] PATCH (was Formulator acts funny for 2-character options)

Jean Jordaan jean at upfrontsystems.co.za
Tue Aug 19 12:23:51 EDT 2003


Hmm, was a bit hasty. The fix is needed in a couple of places
in Widget.py and Validator.py .. New patch attached.

-- 
Jean Jordaan
http://www.upfrontsystems.co.za
-------------- next part --------------
diff --exclude='*.pyc' --exclude='*~' --exclude='.*' -ru /usr/local/zope/Products/Formulator-1.4.1/Validator.py Formulator/Validator.py
--- /usr/local/zope/Products/Formulator-1.4.1/Validator.py	2003-05-16 17:44:47.000000000 +0200
+++ Formulator/Validator.py	2003-08-19 11:10:14.000000000 +0200
@@ -7,6 +7,19 @@
 from urlparse import urljoin
 from Errors import ValidationError
 
+def _splitItem(item):
+    from types import StringType
+    if isinstance(item, StringType):
+        item_text = item
+        item_value = item
+    else:
+        try:
+            item_text, item_value = item
+        except ValueError:
+            item_text = item
+            item_value = item
+    return item_text, item_value
+
 class Validator:
     """Validates input and possibly transforms it to output.
     """
@@ -366,11 +379,7 @@
         
         # get the text and the value from the list of items
         for item in field.get_value('items'):
-            try:
-                item_text, item_value = item
-            except ValueError:
-                item_text = item
-                item_value = item
+            item_text, item_value = _splitItem(item) 
             
             # check if the value is equal to the string/unicode version of
             # item_value; if that's the case, we can return the *original*
@@ -435,11 +444,7 @@
         # create a dictionary of possible values
         value_dict = {}
         for item in field.get_value('items'):
-            try:
-                item_text, item_value = item
-            except ValueError:
-                item_text = item
-                item_value = item
+            item_text, item_value = _splitItem(item) 
             value_dict[item_value] = 0
 
         # check whether all values are in dictionary
@@ -677,4 +682,3 @@
     
 DateTimeValidatorInstance = DateTimeValidator()
         
-    
diff --exclude='*.pyc' --exclude='*~' --exclude='.*' -ru /usr/local/zope/Products/Formulator-1.4.1/Widget.py Formulator/Widget.py
--- /usr/local/zope/Products/Formulator-1.4.1/Widget.py	2003-07-04 12:47:48.000000000 +0200
+++ Formulator/Widget.py	2003-08-19 11:05:53.000000000 +0200
@@ -3,6 +3,19 @@
 from DocumentTemplate.DT_Util import html_quote
 from DateTime import DateTime
 
+def _splitItem(item):
+    from types import StringType
+    if isinstance(item, StringType):
+        item_text = item
+        item_value = item
+    else:
+        try:
+            item_text, item_value = item
+        except ValueError:
+            item_text = item
+            item_value = item
+    return item_text, item_value
+
 class Widget:
     """A field widget that knows how to display itself as HTML.
     """
@@ -392,12 +405,7 @@
         selected_found = 0
         rendered_items = []
         for item in items:
-            try:
-                item_text, item_value = item
-            except ValueError:
-                item_text = item
-                item_value = item
-
+            item_text, item_value = _splitItem(item) 
                 
             if item_value == value and not selected_found:
                 rendered_item = self.render_selected_item(item_text,
@@ -448,11 +456,7 @@
         css_class = field.get_value('css_class')
         rendered_items = []
         for item in items:
-            try:
-                item_text, item_value = item
-            except ValueError:
-                item_text = item
-                item_value = item
+            item_text, item_value = _splitItem(item) 
 
             if item_value in value:
                 rendered_item = self.render_selected_item(item_text,
@@ -476,11 +480,7 @@
         items = field.get_value('items')
         d = {}
         for item in items:
-            try:
-                item_text, item_value = item
-            except ValueError:
-                item_text = item
-                item_value = item
+            item_text, item_value = _splitItem(item) 
             d[item_value] = item_text
         result = []
         for e in value:
@@ -885,6 +885,3 @@
     else:
         return apply(render_tag, (tag,), kw) + " />"
          
-
-
-


More information about the Zope mailing list