[Checkins] SVN: z3c.form/trunk/ Provide a better fix for the bug
Roger fixed already. Also provided a
Stephan Richter
srichter at cosmos.phy.tufts.edu
Fri Jun 1 16:49:15 EDT 2007
Log message for revision 76137:
Provide a better fix for the bug Roger fixed already. Also provided a
comprehensive test for it.
Changed:
U z3c.form/trunk/CHANGES.txt
U z3c.form/trunk/src/z3c/form/term.py
U z3c.form/trunk/src/z3c/form/term.txt
-=-
Modified: z3c.form/trunk/CHANGES.txt
===================================================================
--- z3c.form/trunk/CHANGES.txt 2007-06-01 20:47:35 UTC (rev 76136)
+++ z3c.form/trunk/CHANGES.txt 2007-06-01 20:49:14 UTC (rev 76137)
@@ -2,15 +2,22 @@
CHANGES
=======
+Version 1.3.0 (5/31/2007)
+-------------------------
+
+- Bug: When fields only had a vocabulary name, the choice terms adaptation
+ would fail, since the field was not bound. This has now been corrected.
+
Version 1.2.0 (5/30/2007)
-------------------------
-- Added ability to change the button action title using an IValue adapter.
+- Feature: Added ability to change the button action title using an IValue
+ adapter.
Version 1.1.0 (5/30/2007)
-------------------------
-- Added compatibility for Zope 3.3 and thus Zope 2.10.
+- Feature: Added compatibility for Zope 3.3 and thus Zope 2.10.
Version 1.0.0 (5/24/2007)
Modified: z3c.form/trunk/src/z3c/form/term.py
===================================================================
--- z3c.form/trunk/src/z3c/form/term.py 2007-06-01 20:47:35 UTC (rev 76136)
+++ z3c.form/trunk/src/z3c/form/term.py 2007-06-01 20:49:14 UTC (rev 76137)
@@ -62,7 +62,9 @@
self.form = form
self.field = field
self.widget = widget
- self.terms = field.bind(self.context).vocabulary
+ if field.vocabulary is None:
+ field = field.bind(context)
+ self.terms = field.vocabulary
class BoolTerms(Terms):
Modified: z3c.form/trunk/src/z3c/form/term.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/term.txt 2007-06-01 20:47:35 UTC (rev 76136)
+++ z3c.form/trunk/src/z3c/form/term.txt 2007-06-01 20:49:14 UTC (rev 76137)
@@ -84,6 +84,35 @@
>>> [entry.title for entry in terms]
[u'bad', u'okay', u'good']
+Sometimes choice fields only specify a vocabulary name and the actual
+vocabulary is looked up at run time.
+
+ >>> ratingField2 = zope.schema.Choice(
+ ... title=u'Rating',
+ ... vocabulary='Ratings')
+
+Initially we get an error because the "Ratings" vocabulary is not defined:
+
+ >>> terms = term.ChoiceTerms(None, None, None, ratingField2, None)
+ Traceback (most recent call last):
+ ...
+ VocabularyRegistryError: unknown vocabulary: 'Ratings'
+
+Let's now register the vocabulary under this name:
+
+ >>> def RatingsVocabulary(obj):
+ ... return ratings
+
+ >>> from zope.schema import vocabulary
+ >>> vr = vocabulary.getVocabularyRegistry()
+ >>> vr.register('Ratings', RatingsVocabulary)
+
+We should now be able to get all terms as before:
+
+ >>> terms = term.ChoiceTerms(None, None, None, ratingField2, None)
+ >>> [entry.title for entry in terms]
+ [u'bad', u'okay', u'good']
+
A similar terms implementation exists for a ``Bool`` field:
>>> truthField = zope.schema.Bool()
More information about the Checkins
mailing list