Skip to main content

Utility-based Vocabulary Registry

Project description

This Zope 3 package provides a zope.schema vocabulary registry that uses utilities to look up vocabularies.

Component-based Vocabulary Registry

This package provides a vocabulary registry for zope.schema, based on the component architecture.

It replaces the zope.schema’s simple vocabulary registry when zope.app.schema package is imported, so it’s done automatically. All we need is provide vocabulary factory utilities:

>>> from zope.component import provideUtility
>>> from zope.schema.interfaces import IVocabularyFactory
>>> from zope.schema.vocabulary import SimpleTerm
>>> from zope.schema.vocabulary import SimpleVocabulary
>>> def SomeVocabulary(context=None):
...     terms = [SimpleTerm(1), SimpleTerm(2)]
...     return SimpleVocabulary(terms)
>>> provideUtility(SomeVocabulary, IVocabularyFactory,
...                name='SomeVocabulary')

Now we can get the vocabulary using standard zope.schema way:

>>> from zope.schema.vocabulary import getVocabularyRegistry
>>> vr = getVocabularyRegistry()
>>> voc = vr.get(None, 'SomeVocabulary')
>>> [term.value for term in voc]
[1, 2]

CHANGES

1.0.0 (2013-03-01)

  • Added support for Python 3.3.

  • Replaced deprecated zope.interface.implements usage with equivalent zope.interface.implementer decorator.

  • Dropped support for Python 2.4 and 2.5.

  • Initial release independent of zope.app.schema.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zope.vocabularyregistry-1.0.0.zip (14.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page