[Zope3-checkins] SVN: Zope3/trunk/ Fixed issue 371.

Stephan Richter srichter at cosmos.phy.tufts.edu
Wed Mar 2 10:09:47 EST 2005


Log message for revision 29381:
  Fixed issue 371.
  
  

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 14:27:35 UTC (rev 29380)
+++ Zope3/trunk/doc/CHANGES.txt	2005-03-02 15:09:47 UTC (rev 29381)
@@ -495,6 +495,8 @@
 
     Bug Fixes
 
+      - Fixed issue #371: OrderedMultiSelectWidget ignores setRenderedValue
+
       - Fixed issue #360: MultiSelectWidget configured for ISet but creates
                           list
                           

Modified: Zope3/trunk/doc/TODO.txt
===================================================================
--- Zope3/trunk/doc/TODO.txt	2005-03-02 14:27:35 UTC (rev 29380)
+++ Zope3/trunk/doc/TODO.txt	2005-03-02 15:09:47 UTC (rev 29381)
@@ -92,8 +92,6 @@
 
 * 369: DAV is hosed on the trunk
 
-* 371: OrderedMultiSelectWidget ignores setRenderedValue
-
 * 372: WidgetInputError.doc is broken
 
 * 373: Adding objects requires permission zope.app.dublincore.change 

Modified: Zope3/trunk/src/zope/app/form/browser/itemswidgets.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/itemswidgets.py	2005-03-02 14:27:35 UTC (rev 29380)
+++ Zope3/trunk/src/zope/app/form/browser/itemswidgets.py	2005-03-02 15:09:47 UTC (rev 29381)
@@ -545,22 +545,28 @@
 
     def choices(self):
         """Return a set of tuples (text, value) that are available."""
-        # Not all content object must necessarily support the attributes
+        # Not all content objects must necessarily support the attributes
         if hasattr(self.context.context, self.context.__name__):
-            selected_values = self.context.get(self.context.context)
+            available_values = self.context.get(self.context.context)
         else:
-            selected_values = []
+            available_values = []
         return [{'text': self.textForValue(term), 'value': term.token}
                 for term in self.vocabulary
-                if term.value not in selected_values]
+                if term.value not in available_values]
         
     def selected(self):
         """Return a list of tuples (text, value) that are selected."""
-        # Not all content object must necessarily support the attributes
-        if not hasattr(self.context.context, self.context.__name__):
-            return []
+        # Get form values
+        values = self._getFormValue()
+        # Not all content objects must necessarily support the attributes
+        if hasattr(self.context.context, self.context.__name__):
+            # merge in values from content 
+            for value in self.context.get(self.context.context):
+                if value not in values:
+                    values.append(value)
+                
         terms = [self.vocabulary.getTerm(value)
-                 for value in self.context.get(self.context.context)]
+                 for value in values]
         return [{'text': self.textForValue(term), 'value': term.token}
                 for term in terms]
     

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 14:27:35 UTC (rev 29380)
+++ Zope3/trunk/src/zope/app/form/browser/tests/test_itemswidget.py	2005-03-02 15:09:47 UTC (rev 29381)
@@ -448,8 +448,13 @@
 
     def test_selected(self):
         widget = self._makeWidget(nums=['one'])
+        widget._data = ['two']
         selected = [select['text'] for select in widget.selected()]
         selected.sort()
+        self.assertEqual(selected, ['One', 'Two'])
+        widget._data = ['one']
+        selected = [select['text'] for select in widget.selected()]
+        selected.sort()
         self.assertEqual(selected, ['One'])
     
 



More information about the Zope3-Checkins mailing list