[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/ Merged bugfix for IntWidget (it would not render 0) from trunk (28918:28920).

Gintautas Miliauskas gintas at pov.lt
Mon Jan 24 10:21:12 EST 2005


Log message for revision 28922:
  Merged bugfix for IntWidget (it would not render 0) from trunk (28918:28920).
  

Changed:
  U   Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_intwidget.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_textwidget.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/textwidgets.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/widget.py

-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_intwidget.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_intwidget.py	2005-01-24 15:14:59 UTC (rev 28921)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_intwidget.py	2005-01-24 15:21:12 UTC (rev 28922)
@@ -28,7 +28,7 @@
 
 class IntWidgetTest(SimpleInputWidgetTest):
     """Documents and tests the int widget.
-        
+
         >>> verifyClass(IInputWidget, IntWidget)
         True
     """

Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_textwidget.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_textwidget.py	2005-01-24 15:14:59 UTC (rev 28921)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_textwidget.py	2005-01-24 15:21:12 UTC (rev 28922)
@@ -120,7 +120,7 @@
     """
     There was a bug that caused the value attribute to be set to
     'value' under these circumstances.
-    
+
     >>> from zope.publisher.browser import TestRequest
     >>> from zope.schema import TextLine
     >>> field = TextLine(__name__='foo', title=u'on',

Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/textwidgets.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/textwidgets.py	2005-01-24 15:14:59 UTC (rev 28921)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/textwidgets.py	2005-01-24 15:21:12 UTC (rev 28922)
@@ -120,29 +120,23 @@
         super(TextWidget, self).__init__(*args)
 
     def __call__(self):
-        displayMaxWidth = self.displayMaxWidth or 0
-        if displayMaxWidth > 0:
-            return renderElement(self.tag,
-                                 type=self.type,
-                                 name=self.name,
-                                 id=self.name,
-                                 value=self._getFormValue() or '',
-                                 cssClass=self.cssClass,
-                                 style=self.style,
-                                 size=self.displayWidth,
-                                 maxlength=displayMaxWidth,
-                                 extra=self.extra)
-        else:
-            return renderElement(self.tag,
-                                 type=self.type,
-                                 name=self.name,
-                                 id=self.name,
-                                 value=self._getFormValue() or '',
-                                 cssClass=self.cssClass,
-                                 style=self.style,
-                                 size=self.displayWidth,
-                                 extra=self.extra)
+        value = self._getFormValue()
+        if value is None or value == self.context.missing_value:
+            value = ''
 
+        kwargs = {'type': self.type,
+                  'name': self.name,
+                  'id': self.name,
+                  'value': value,
+                  'cssClass': self.cssClass,
+                  'style': self.style,
+                  'size': self.displayWidth,
+                  'extra': self.extra}
+        if self.displayMaxWidth:
+            kwargs['maxlength'] = self.displayMaxWidth # XXX This is untested.
+
+        return renderElement(self.tag, **kwargs)
+
     def _toFieldValue(self, input):
         if self.convert_missing_value and input == self._missing:
             value = self.context.missing_value
@@ -150,7 +144,7 @@
             # We convert everything to unicode. This might seem a bit crude,
             # but anything contained in a TextWidget should be representable
             # as a string. Note that you always have the choice of overriding
-            # the method.  
+            # the method.
             try:
                 value = unicode(input)
             except ValueError, v:
@@ -389,6 +383,20 @@
                 return self.context.missing_value
 
 class IntWidget(TextWidget):
+    """Integer number widget.
+
+    Let's make sure that zeroes are rendered properly:
+
+    >>> from zope.schema import Int
+    >>> field = Int(__name__='foo', title=u'on')
+    >>> widget = IntWidget(field, None)
+    >>> widget.setRenderedValue(0)
+
+    >>> 'value="0"' in widget()
+    True
+
+    """
+
     displayWidth = 10
 
     def _toFieldValue(self, input):

Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/widget.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/widget.py	2005-01-24 15:14:59 UTC (rev 28921)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/widget.py	2005-01-24 15:21:12 UTC (rev 28922)
@@ -296,7 +296,7 @@
         except ConversionError, error:
             # ConversionError is already a WidgetInputError
             self._error = error
-            raise self._error            
+            raise self._error
 
         # allow missing values only for non-required fields
         if value == field.missing_value and not field.required:
@@ -448,7 +448,7 @@
         items = kw.items()
         items.sort()
         for key, value in items:
-            if value == None:
+            if value is None:
                 value = key
             attr_list.append(u'%s=%s' % (key, quoteattr(unicode(value))))
 



More information about the Zope3-Checkins mailing list