[Grok-dev] Sample code creating and registring a SimpleVocabulary?
Leonardo Rochael Almeida
leorochael at gmail.com
Tue Aug 28 17:22:08 EDT 2007
wouldn't grok.Utility help here?
On 8/28/07, Sebastian Ware <sebastian at urbantalk.se> wrote:
> So simple and elegant -- thank you very much!!! It took me a couple
> of hours not to figure it out by myself... :)
>
> Mvh Sebastian
>
> 28 aug 2007 kl. 17.49 skrev Kevin Smith:
>
> > Here's one of the ways to do it.
> >
> > Kevin Smith
> >
> >
> >
> > from zope import schema
> > from zope.schema.vocabulary import SimpleVocabulary
> >
> > VARIETALS = """Cabernet Franc
> > Cabernet Sauvignon
> > Chardonnay
> > Chenin Blanc
> > Claret
> > Gewurztraminer
> > Grenache
> > Malbec
> > Marsanne
> > Merlot
> > Petit Syrah
> > Petit Verdot"""
> >
> > class VarietalsSource(object):
> > def __call__(self, context):
> > values = VARIETALS.splitlines()
> > return SimpleVocabulary.fromValues(values)
> > grok.global_utility(VarietalsSource,
> > provides=schema.interfaces.IVocabularyFactory,
> > name=u'VarietalsSource')
More information about the Grok-dev
mailing list