[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/ Fixed issue #293
by removing unused 'value_type' parameter from
Derrick Hudson
dman at dman13.dyndns.org
Wed Jan 19 10:30:05 EST 2005
Log message for revision 28873:
Fixed issue #293 by removing unused 'value_type' parameter from
SequenceWidget's __init__. In addition, __init__ now pays attention to the
'subwidget' parameter instead of always setting self.subwidget to None.
Changed:
U Zope3/branches/ZopeX3-3.0/doc/CHANGES.txt
U Zope3/branches/ZopeX3-3.0/src/zope/app/form/__init__.py
U Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/sequencewidget.py
U Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_sequencewidget.py
-=-
Modified: Zope3/branches/ZopeX3-3.0/doc/CHANGES.txt
===================================================================
--- Zope3/branches/ZopeX3-3.0/doc/CHANGES.txt 2005-01-19 14:26:57 UTC (rev 28872)
+++ Zope3/branches/ZopeX3-3.0/doc/CHANGES.txt 2005-01-19 15:30:03 UTC (rev 28873)
@@ -10,6 +10,8 @@
Bug Fixes
+ - Fixed issue 293 (sequence widget).
+
- Backported several bug fixes made to the DSN parser, including issue
304.
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/form/__init__.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/form/__init__.py 2005-01-19 14:26:57 UTC (rev 28872)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/form/__init__.py 2005-01-19 15:30:03 UTC (rev 28873)
@@ -90,6 +90,6 @@
def __call__(self, context, request):
args = (context, request) + self.args
instance = self._widget_factory(*args)
- for item in self.kw.items():
- setattr(instance, item[0], item[1])
+ for name, value in self.kw.items():
+ setattr(instance, name, value)
return instance
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/sequencewidget.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/sequencewidget.py 2005-01-19 14:26:57 UTC (rev 28872)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/sequencewidget.py 2005-01-19 15:30:03 UTC (rev 28873)
@@ -36,13 +36,13 @@
implements(IInputWidget)
- _type = tuple
+ _type = tuple
_data = () # pre-existing sequence items (from setRenderedValue)
- def __init__(self, context, value_type, request, subwidget=None):
+ def __init__(self, context, request, subwidget=None):
super(SequenceWidget, self).__init__(context, request)
- self.subwidget = None
+ self.subwidget = subwidget
def __call__(self):
"""Render the widget
@@ -234,7 +234,7 @@
return sequence
class TupleSequenceWidget(SequenceWidget):
- pass
+ _type = tuple
class ListSequenceWidget(SequenceWidget):
_type = list
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_sequencewidget.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_sequencewidget.py 2005-01-19 14:26:57 UTC (rev 28872)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_sequencewidget.py 2005-01-19 15:30:03 UTC (rev 28873)
@@ -25,9 +25,11 @@
from zope.app import zapi
from zope.app.tests import ztapi
-from zope.app.form.browser import TextWidget, TupleSequenceWidget
-from zope.app.form.browser import ListSequenceWidget
+from zope.app.form.browser import TextWidget, ObjectWidget
+from zope.app.form.browser import TupleSequenceWidget, ListSequenceWidget
+from zope.app.form.browser import SequenceWidget
from zope.app.form.interfaces import IInputWidget
+from zope.app.form import CustomWidgetFactory
from zope.app.form.browser.tests.test_browserwidget import BrowserWidgetTest
@@ -55,9 +57,7 @@
field = field.bind(self.content)
request = TestRequest(HTTP_ACCEPT_LANGUAGE='pl')
request.form['field.foo'] = u'Foo Value'
- # sequence widgets take value_type as second argument because of double
- # dispatch
- self._widget = self._WidgetFactory(field, TextLine(), request)
+ self._widget = self._WidgetFactory(field, request)
def _FieldFactory(self, **kw):
kw.update({
@@ -83,28 +83,64 @@
self._widget.request.form['field.foo.0.bar'] = u'hi, mum'
self.failUnless(self._widget.hasInput())
+ def test_customWidgetFactory(self):
+ """Verify that the widget can be constructed via the CustomWidgetFactory
+ (Issue #293)
+ """
+
+ value_type = TextLine(__name__=u'bar')
+ self.field = List( __name__=u'foo', value_type=value_type )
+ request = TestRequest()
+
+ # set up the custom widget factory and verify that it works
+ sw = CustomWidgetFactory(ListSequenceWidget)
+ widget = sw(self.field, request)
+ assert widget.subwidget is None
+ assert widget.context.value_type is value_type
+
+ # set up a variant that specifies the subwidget to use and verify it
+ class PollOption(object) : pass
+ ow = CustomWidgetFactory(ObjectWidget, PollOption)
+ sw = CustomWidgetFactory(ListSequenceWidget, subwidget=ow)
+ widget = sw(self.field, request)
+ assert widget.subwidget is ow
+ assert widget.context.value_type is value_type
+
+ def test_subwidget(self):
+ """This test verifies that the specified subwidget is not ignored.
+ (Issue #293)
+ """
+ self.field = List( __name__=u'foo',
+ value_type=TextLine(__name__=u'bar'))
+ request = TestRequest()
+
+ class PollOption(object) : pass
+ ow = CustomWidgetFactory(ObjectWidget, PollOption)
+ widget = SequenceWidget(self.field, request, subwidget=ow)
+ assert widget.subwidget is ow
+
def test_list(self):
self.field = List(
__name__=u'foo',
value_type=TextLine(__name__=u'bar'))
request = TestRequest()
- widget = ListSequenceWidget(self.field, TextLine(), request)
+ widget = ListSequenceWidget(self.field, request)
self.failIf(widget.hasInput())
self.assertEquals(widget.getInputValue(), [])
request = TestRequest(form={'field.foo.add': u'Add bar'})
- widget = ListSequenceWidget(self.field, TextLine(), request)
+ widget = ListSequenceWidget(self.field, request)
self.assert_(widget.hasInput())
self.assertRaises(ValidationError, widget.getInputValue)
request = TestRequest(form={'field.foo.0.bar': u'Hello world!'})
- widget = ListSequenceWidget(self.field, TextLine(), request)
+ widget = ListSequenceWidget(self.field, request)
self.assert_(widget.hasInput())
self.assertEquals(widget.getInputValue(), [u'Hello world!'])
def test_new(self):
request = TestRequest()
- widget = TupleSequenceWidget(self.field, TextLine(), request)
+ widget = TupleSequenceWidget(self.field, request)
self.failIf(widget.hasInput())
self.assertEquals(widget.getInputValue(), ())
check_list = ('input', 'name="field.foo.add"')
@@ -112,7 +148,7 @@
def test_add(self):
request = TestRequest(form={'field.foo.add': u'Add bar'})
- widget = TupleSequenceWidget(self.field, TextLine(), request)
+ widget = TupleSequenceWidget(self.field, request)
self.assert_(widget.hasInput())
self.assertRaises(ValidationError, widget.getInputValue)
check_list = (
@@ -123,13 +159,13 @@
def test_request(self):
request = TestRequest(form={'field.foo.0.bar': u'Hello world!'})
- widget = TupleSequenceWidget(self.field, TextLine(), request)
+ widget = TupleSequenceWidget(self.field, request)
self.assert_(widget.hasInput())
self.assertEquals(widget.getInputValue(), (u'Hello world!',))
def test_existing(self):
request = TestRequest()
- widget = TupleSequenceWidget(self.field, TextLine(), request)
+ widget = TupleSequenceWidget(self.field, request)
widget.setRenderedValue((u'existing',))
self.assert_(widget.hasInput())
self.assertEquals(widget.getInputValue(), (u'existing',))
@@ -155,7 +191,7 @@
request = TestRequest(form={'field.foo.remove_0': u'Hello world!',
'field.foo.0.bar': u'existing', 'field.foo.1.bar': u'second',
'remove-selected-items-of-seq-field.foo': u'Remove selected items'})
- widget = TupleSequenceWidget(self.field, TextLine(), request)
+ widget = TupleSequenceWidget(self.field, request)
widget.setRenderedValue((u'existing', u'second'))
self.assertEquals(widget.getInputValue(), (u'second',))
check_list = (
@@ -168,7 +204,7 @@
def test_min(self):
request = TestRequest()
self.field.min_length = 2
- widget = TupleSequenceWidget(self.field, TextLine(), request)
+ widget = TupleSequenceWidget(self.field, request)
widget.setRenderedValue((u'existing',))
self.assertEquals(widget.getInputValue(), (u'existing',))
check_list = (
@@ -183,7 +219,7 @@
def test_max(self):
request = TestRequest()
self.field.max_length = 1
- widget = TupleSequenceWidget(self.field, TextLine(), request)
+ widget = TupleSequenceWidget(self.field, request)
widget.setRenderedValue((u'existing',))
self.assertEquals(widget.getInputValue(), (u'existing',))
s = widget()
@@ -192,7 +228,7 @@
def test_anonymousfield(self):
self.field = Tuple(__name__=u'foo', value_type=TextLine())
request = TestRequest()
- widget = TupleSequenceWidget(self.field, TextLine(), request)
+ widget = TupleSequenceWidget(self.field, request)
widget.setRenderedValue((u'existing',))
s = widget()
check_list = (
More information about the Zope3-Checkins
mailing list