[Zope3-checkins] SVN: Zope3/trunk/ Fixed issue 360 by basically
following Jim's suggestion.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Wed Mar 2 09:27:35 EST 2005
Log message for revision 29380:
Fixed issue 360 by basically following Jim's suggestion.
Changed:
U Zope3/trunk/doc/CHANGES.txt
U Zope3/trunk/doc/TODO.txt
U Zope3/trunk/src/zope/app/form/browser/itemswidgets.py
U Zope3/trunk/src/zope/app/form/browser/tests/test_itemswidget.py
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2005-03-02 07:42:24 UTC (rev 29379)
+++ Zope3/trunk/doc/CHANGES.txt 2005-03-02 14:27:35 UTC (rev 29380)
@@ -495,6 +495,11 @@
Bug Fixes
+ - Fixed issue #360: MultiSelectWidget configured for ISet but creates
+ list
+
+ The correct type of the collection field is now discovered and used.
+
- Addressed issue #348: ZCML hides import errors
I tried really hard to get a better error message, but it is not
Modified: Zope3/trunk/doc/TODO.txt
===================================================================
--- Zope3/trunk/doc/TODO.txt 2005-03-02 07:42:24 UTC (rev 29379)
+++ Zope3/trunk/doc/TODO.txt 2005-03-02 14:27:35 UTC (rev 29380)
@@ -90,8 +90,6 @@
* 356: Copy and Paste does not handle exceptions raised by __setitem__
-* 360: MultiSelectWidget configured for ISet but creates list
-
* 369: DAV is hosed on the trunk
* 371: OrderedMultiSelectWidget ignores setRenderedValue
Modified: Zope3/trunk/src/zope/app/form/browser/itemswidgets.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/itemswidgets.py 2005-03-02 07:42:24 UTC (rev 29379)
+++ Zope3/trunk/src/zope/app/form/browser/itemswidgets.py 2005-03-02 14:27:35 UTC (rev 29380)
@@ -16,8 +16,9 @@
$Id$
"""
__docformat__ = 'restructuredtext'
+import sets
+from xml.sax.saxutils import escape
-from xml.sax.saxutils import escape
from zope.interface import implements
from zope.i18n import translate
from zope.schema.interfaces import ValidationError, InvalidValue
@@ -188,10 +189,19 @@
if not isinstance(input, list):
input = [input]
try:
- return self.convertTokensToValues(input)
+ values = self.convertTokensToValues(input)
except InvalidValue, e:
raise ConversionError("Invalid value", e)
+ # All AbstractCollection fields have a `_type` attribute specifying
+ # the type of collection. Use it to generate the correct type,
+ # otherwise return a list.
+ if hasattr(self.context, '_type'):
+ return self.context._type(values)
+ else:
+ return values
+
+
def _getDefault(self):
# Return the default value for this widget;
# may be overridden by subclasses.
@@ -526,6 +536,7 @@
class MultiSelectWidget(ItemsMultiEditWidgetBase):
"""Provide a selection list for the list to be selected."""
+
class OrderedMultiSelectWidget(ItemsMultiEditWidgetBase):
"""A multi-selection widget with ordering support."""
Modified: Zope3/trunk/src/zope/app/form/browser/tests/test_itemswidget.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/tests/test_itemswidget.py 2005-03-02 07:42:24 UTC (rev 29379)
+++ Zope3/trunk/src/zope/app/form/browser/tests/test_itemswidget.py 2005-03-02 14:27:35 UTC (rev 29380)
@@ -15,10 +15,11 @@
$Id$
"""
+import sets
import unittest
from zope.interface import Interface, implements
-from zope.schema import Choice, List
+from zope.schema import Choice, List, Set, TextLine
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
from zope.publisher.browser import TestRequest
@@ -58,7 +59,13 @@
value_type=choice,
required=False)
+ letters = Set(
+ title=u"Letters",
+ description=u"The Letters",
+ value_type=choice,
+ required=False)
+
class Collector(object):
implements(ICollector)
@@ -411,7 +418,19 @@
['<input', 'type="hidden"', 'value="token2"', 'id="field.numbers"',
'name="field.numbers:list"', 'value="token3"'])
+ def test_getInputValue(self):
+ widget = self._makeWidget(form={'field.numbers': ['token2','token3']})
+ widget.setPrefix('field.')
+ self.assertEqual(widget.getInputValue(), ['two', 'three'])
+ self._field = ICollector.get('letters')
+ widget = self._makeWidget(form={'field.letters': ['token2','token3']})
+ widget.setPrefix('field.')
+ self.assertEqual(widget.getInputValue(), sets.Set(['two', 'three']))
+ self._field = ICollector.get('numbers')
+
+
+
class MultiSelectWidgetTest(ItemsMultiEditWidgetBaseTest):
_widget = MultiSelectWidget
More information about the Zope3-Checkins
mailing list