Skip to main content

Utility-based Vocabulary Registry

Project description

zope.vocabularyregistry

Latest release Supported Python versions https://travis-ci.org/zopefoundation/zope.vocabularyregistry.svg?branch=master https://coveralls.io/repos/github/zopefoundation/zope.vocabularyregistry/badge.svg?branch=master

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.vocabularyregistry package is imported, so it’s done automatically. All we need is provide vocabulary factory utilities:

>>> import zope.vocabularyregistry
>>> 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]

Configuration

This package provides configuration that ensures the vocabulary registry is established:

>>> from zope.configuration import xmlconfig
>>> _ = xmlconfig.string(r"""
... <configure xmlns="http://namespaces.zope.org/zope" i18n_domain="zope">
...   <include package="zope.vocabularyregistry" />
... </configure>
... """)

CHANGES

1.1.0 (2018-11-30)

  • Ensure that a convtext is provided when looking up the vocabulary factory.

  • Drop support for Python 2.6 and 3.3.

  • Add support for Python 3.5, 3.6, 3.7, PyPy and PyPy3.

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.1.0.tar.gz (8.2 kB view hashes)

Uploaded Source

Built Distribution

zope.vocabularyregistry-1.1.0-py2.py3-none-any.whl (8.0 kB view hashes)

Uploaded Python 2 Python 3

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