[Checkins] SVN: z3c.form/trunk/src/z3c/form/widget. It sometimes happens that the sequence widget has the

Stephan Richter srichter at cosmos.phy.tufts.edu
Mon Jun 4 02:45:36 EDT 2007


Log message for revision 76276:
  It sometimes happens that the sequence widget has the 
  no-value token as one element. This caused displayValue() to 
  fail,since it tried to find a term for it. For now we simply 
  ignore the no-value token.
  

Changed:
  U   z3c.form/trunk/src/z3c/form/widget.py
  U   z3c.form/trunk/src/z3c/form/widget.txt

-=-
Modified: z3c.form/trunk/src/z3c/form/widget.py
===================================================================
--- z3c.form/trunk/src/z3c/form/widget.py	2007-06-04 06:19:18 UTC (rev 76275)
+++ z3c.form/trunk/src/z3c/form/widget.py	2007-06-04 06:45:36 UTC (rev 76276)
@@ -155,6 +155,9 @@
     def displayValue(self):
         value = []
         for token in self.value:
+            # Ignore no value entries. They are in the request only.
+            if token == self.noValueToken:
+                continue
             term = self.terms.getTermByToken(token)
             if zope.schema.interfaces.ITitledTokenizedTerm.providedBy(term):
                 value.append(translate(

Modified: z3c.form/trunk/src/z3c/form/widget.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/widget.txt	2007-06-04 06:19:18 UTC (rev 76275)
+++ z3c.form/trunk/src/z3c/form/widget.txt	2007-06-04 06:45:36 UTC (rev 76276)
@@ -381,6 +381,13 @@
   >>> seqWidget.extract()
   []
 
+If the no-value token has been selected, it is returned without further
+verification:
+
+  >>> seqWidget.request = TestRequest(form={'seq': [seqWidget.noValueToken]})
+  >>> seqWidget.extract()
+  ['--NOVALUE--']
+
 Since the value of the widget is a tuple of tokens, when displaying the
 values, they have to be converted to the title of the term:
 
@@ -388,6 +395,14 @@
   >>> seqWidget.displayValue
   [u'Value 1', u'Value 2']
 
+When input forms are directly switched to display forms within the same
+request, it can happen that the value contains the "--NOVALUE--" token
+entry. This entry should be silently ignored:
+
+  >>> seqWidget.value = (seqWidget.noValueToken,)
+  >>> seqWidget.displayValue
+  []
+
 To demonstrate how the terms is automatically chosen by a widget, we should
 instantiate a field widget. Let's do this with a choice field:
 



More information about the Checkins mailing list