[Grok-dev] Sample code creating and registring a SimpleVocabulary?
Kevin Smith
kevin at mcweekly.com
Tue Aug 28 11:49:09 EDT 2007
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')
Sebastian Ware wrote:
> Does anyone have some sample code showing how to create and register a
> SimpleVocabulary in Grok? (I'll be happy to write
> howto/recipe/tutorial... when I get it to work) I intend to use it
> with a choice widget, but I only have Zope 3 examples, and they all
> require some ZCML...
>
> Mvh Sebastian
>
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev
>
More information about the Grok-dev
mailing list