[Zope3-checkins] CVS: Zope3/src/zope/schema - vocabulary.py:1.8
Casey Duncan
casey@zope.com
Sat, 31 May 2003 01:47:42 -0400
Update of /cvs-repository/Zope3/src/zope/schema
In directory cvs.zope.org:/tmp/cvs-serv14217
Modified Files:
vocabulary.py
Log Message:
Make sure tokenized vocabularies validate against the value not the token
=== Zope3/src/zope/schema/vocabulary.py 1.7 => 1.8 ===
--- Zope3/src/zope/schema/vocabulary.py:1.7 Fri May 30 17:46:47 2003
+++ Zope3/src/zope/schema/vocabulary.py Sat May 31 01:47:41 2003
@@ -59,6 +59,12 @@
# XXX can't validate without vocabulary, and can't get
# vocabulary without context
return
+ if IVocabularyTokenized.isImplementedBy(self.vocabulary):
+ # Get the term value from the provided token value
+ try:
+ value = self.vocabulary.getTermByToken(value).value
+ except LookupError:
+ raise ValidationError(errornames.ConstraintNotSatisfied, v)
if value not in self.vocabulary:
raise ValidationError(errornames.ConstraintNotSatisfied,
value)
@@ -90,6 +96,15 @@
vocab = self.vocabulary
if vocab is None:
raise ValueError("can't validate value without vocabulary")
+ if IVocabularyTokenized.isImplementedBy(vocab):
+ # Get the term values from the provided token values
+ for token in value:
+ try:
+ v = vocab.getTermByToken(token).value
+ except LookupError:
+ raise ValidationError(errornames.ConstraintNotSatisfied, v)
+ if v not in vocab:
+ raise ValidationError(errornames.ConstraintNotSatisfied, v)
for v in value:
if v not in vocab:
raise ValidationError(errornames.ConstraintNotSatisfied, v)