On Sat, Apr 15, 2006 at 08:41:57AM -0700, Ruben Gutierrez wrote:
> I'm having trouble understanding some of the semantics or conventions with
> Zope. One simple question I have is how do I create a list of selectable
> values in a form. I understand you can use a Choice object, but I would like
> to populate the list with all available objects of a specific type, within a
> specific container. For example, I have a form which requests an address.
> How do I populate the State (e.g., CA, HI, NY) field from a list of stored
> State objects? I don't want to include all states, as some may not be
> relevant (maybe the form is region-specific). But, I also don't want to
> statically list the states in a Choice declaration, either.
Sounds like a classic use case for a vocabulary.
from zope.interface import implements
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
from zope.app.schema.interfaces import IVocabularyFactory
terms=[SimpleTerm(name,title=name) for name in context.keys()]
The vocabulary factory makes use of the provided context object (which is
the current content object when editing a form. Just use the vocabulary in a
Zope3-users mailing list