[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/form/browser/ handle a TODO: add a multi-select widget that returns a set

Fred L. Drake, Jr. fdrake at gmail.com
Thu May 12 14:32:06 EDT 2005


Log message for revision 30342:
  handle a TODO: add a multi-select widget that returns a set

Changed:
  U   Zope3/trunk/src/zope/app/form/browser/__init__.py
  U   Zope3/trunk/src/zope/app/form/browser/configure.zcml
  U   Zope3/trunk/src/zope/app/form/browser/itemswidgets.py

-=-
Modified: Zope3/trunk/src/zope/app/form/browser/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/__init__.py	2005-05-12 16:02:42 UTC (rev 30341)
+++ Zope3/trunk/src/zope/app/form/browser/__init__.py	2005-05-12 18:32:06 UTC (rev 30342)
@@ -60,6 +60,7 @@
 # Widgets that let you choose several items from a list
 # These widgets are multi-views on (field, vocabulary)
 from zope.app.form.browser.itemswidgets import MultiSelectWidget
+from zope.app.form.browser.itemswidgets import MultiSelectSetWidget
 from zope.app.form.browser.itemswidgets import MultiCheckBoxWidget
 from zope.app.form.browser.itemswidgets import OrderedMultiSelectWidget
 

Modified: Zope3/trunk/src/zope/app/form/browser/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/configure.zcml	2005-05-12 16:02:42 UTC (rev 30341)
+++ Zope3/trunk/src/zope/app/form/browser/configure.zcml	2005-05-12 18:32:06 UTC (rev 30342)
@@ -352,13 +352,12 @@
   <!-- These widgets are minimal and only support lists with unique members,
        without ordering capabilities -->
 
-  <!-- TODO: This will generate a list and not a set, so be careful!!!-->
   <view
       type="zope.publisher.interfaces.browser.IBrowserRequest"
       for="zope.schema.interfaces.ISet
            zope.schema.interfaces.IVocabularyTokenized"
       provides="zope.app.form.interfaces.IInputWidget"
-      factory=".MultiSelectWidget"
+      factory=".MultiSelectSetWidget"
       permission="zope.Public"
       />
 

Modified: Zope3/trunk/src/zope/app/form/browser/itemswidgets.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/itemswidgets.py	2005-05-12 16:02:42 UTC (rev 30341)
+++ Zope3/trunk/src/zope/app/form/browser/itemswidgets.py	2005-05-12 18:32:06 UTC (rev 30342)
@@ -545,6 +545,16 @@
     """Provide a selection list for the list to be selected."""
 
 
+class MultiSelectSetWidget(MultiSelectWidget):
+    """Provide a selection list for the set to be selected."""
+
+    def _toFieldValue(self, input):
+        value = super(MultiSelectSetWidget, self)._toFieldValue(input)
+        if isinstance(value, list):
+            value = sets.Set(value)
+        return value
+
+
 class OrderedMultiSelectWidget(ItemsMultiEditWidgetBase):
     """A multi-selection widget with ordering support."""
 



More information about the Zope3-Checkins mailing list