[Zope3-checkins] CVS: Zope3/src/zope/schema - vocabulary.py:1.19

Gary Poster gary at zope.com
Wed Jan 28 18:08:13 EST 2004


Update of /cvs-repository/Zope3/src/zope/schema
In directory cvs.zope.org:/tmp/cvs-serv20158

Modified Files:
	vocabulary.py 
Log Message:
Make it possible to easily use VocabularyFields in zcml declarations (interfaces).



=== Zope3/src/zope/schema/vocabulary.py 1.18 => 1.19 ===
--- Zope3/src/zope/schema/vocabulary.py:1.18	Tue Nov  4 22:08:11 2003
+++ Zope3/src/zope/schema/vocabulary.py	Wed Jan 28 18:07:42 2004
@@ -29,6 +29,7 @@
 from zope.schema.interfaces import IVocabularyUniqueListField
 from zope.schema.interfaces import IVocabulary, IVocabularyTokenized
 from zope.schema.interfaces import ITokenizedTerm
+from zope.schema.interfaces import IFromUnicode
 
 class ContainerValidatedProperty(ValidatedProperty):
 
@@ -72,7 +73,7 @@
 
     The value is a single value from the vocabulary.
     """
-    implements(IVocabularyField)
+    implements(IVocabularyField, IFromUnicode)
 
     def _validate(self, value):
         if self.vocabulary is None:
@@ -84,7 +85,20 @@
         if value not in self.vocabulary:
             raise ValidationError(errornames.ConstraintNotSatisfied,
                                   value)
-
+    
+    def fromUnicode(self, str):
+        """
+        >>> t = VocabularyField(
+        ...     vocabulary=SimpleVocabulary.fromValues([u'foo',u'bar']))
+        >>> t.fromUnicode(u"baz")
+        Traceback (most recent call last):
+        ...
+        ValidationError: (u'Constraint not satisfied', u'baz')
+        >>> t.fromUnicode(u"foo")
+        u'foo'
+        """
+        self.validate(str)
+        return str
 
 class VocabularyMultiField(MinMaxLen, BaseVocabularyField):
     """Field that adds support for use of an external vocabulary.




More information about the Zope3-Checkins mailing list