[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form - vocabularywidget.py:1.8
Fred L. Drake, Jr.
fred@zope.com
Wed, 28 May 2003 14:26:41 -0400
Update of /cvs-repository/Zope3/src/zope/app/browser/form
In directory cvs.zope.org:/tmp/cvs-serv3671
Modified Files:
vocabularywidget.py
Log Message:
- when a form is submitted with a value that doesn't match a
vocabulary value (for a vocabulary field), raise a ValidationError
- use the ITokenizedTerm interface properly
=== Zope3/src/zope/app/browser/form/vocabularywidget.py 1.7 => 1.8 ===
--- Zope3/src/zope/app/browser/form/vocabularywidget.py:1.7 Wed May 28 13:09:01 2003
+++ Zope3/src/zope/app/browser/form/vocabularywidget.py Wed May 28 14:26:40 2003
@@ -29,7 +29,7 @@
from zope.component import getView
from zope.schema.interfaces import IIterableVocabulary, IVocabularyQuery
from zope.schema.interfaces import IIterableVocabularyQuery
-from zope.schema.interfaces import IVocabularyTokenized
+from zope.schema.interfaces import IVocabularyTokenized, ValidationError
# These widget factories delegate to the vocabulary on the field.
@@ -106,7 +106,7 @@
"<input type='%s' value='%s' name='%s' %s/>"
"</td>\n <td>%s</td>"
"</tr>\n"
- % (type, term.value, name, flag, self.textForValue(term)))
+ % (type, term.token, name, flag, self.textForValue(term)))
L.append("</table>")
return ''.join(L)
@@ -291,19 +291,18 @@
rendered_items = []
count = 0
for term in self.context.vocabulary:
- item_value = term.value
item_text = self.textForValue(term)
- if item_value in values:
+ if term.value in values:
rendered_item = self.renderSelectedItem(count,
item_text,
- item_value,
+ term.token,
self.name,
cssClass)
else:
rendered_item = self.renderItem(count,
item_text,
- item_value,
+ term.token,
self.name,
cssClass)
@@ -498,9 +497,17 @@
else:
if self.query_index < 0:
self.query_index = 0
- self.query_selections = get(self.query_selections_name, [])
- if not isinstance(self.query_selections, list):
- self.query_selections = [self.query_selections]
+ QS = get(self.query_selections_name, [])
+ if not isinstance(QS, list):
+ QS = [QS]
+ self.query_selections = []
+ for token in QS:
+ try:
+ term = self.vocabulary.getTermByToken(token)
+ except LookupError:
+ raise ValidationError
+ else:
+ self.query_selections.append(term.value)
def renderQueryInput(self):
# There's no query support, so we can't actually have input.