[z3-five] Using vocabularies for Choice fields where the vocabulary is acquired

Hanno Schlichting plone at hannosch.info
Wed Dec 27 20:48:41 CET 2006


Hi Martin,

Martin Aspeli wrote:
> Hi,
> 
> I want to use a vocabulary in a zope.schema.Choice field in a formlib 
> form. From Philipp's book, I see how to hook a vocabulary up to a form, 
> but this either uses hard coded simple items or the utility registry (a 
> utility vocabulary).
> 
> I need to present a list of portal types, acquired by traversing to the 
> portal_types tool and asking it for a list of type ids (or id/name 
> combinations, probably).
> 
> To do so, however, I need a context so that I can acquire the 
> portal_types tool. Both a module-level vocabulary and a utility 
> vocabulary suffers from being context-less. However, at least at the 
> time when the form is rendered I will have a context.

I'm not sure that my approach is by any means good or advisable but you
could take a look at the PortalTypesVocabulary in
plone.app.controlpanel.vocabularies and its usage on the search control
panel defined by the ISearchSchema in search.py in the same package.

The code can be found at
http://dev.plone.org/plone/browser/plone.app.controlpanel/trunk/plone/app/controlpanel

> Can anyone point me to some code or documentation that shows how to wait 
> until run-time to define the vocabulary, and gives me the current 
> context from which to do so?

Maybe you can even just use the vocabulary I've already written in which
case we might need to move it to a more general package.

Hanno



More information about the z3-five mailing list