Skip to content

Instantly share code, notes, and snippets.

@toutpt
Created August 14, 2012 15:43
Show Gist options
  • Save toutpt/3350395 to your computer and use it in GitHub Desktop.
Save toutpt/3350395 to your computer and use it in GitHub Desktop.
registry vocabulary
from zope import component
from zope import interface
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
from zope.schema.interfaces import IVocabularyFactory
from plone.i18n.normalizer.base import baseNormalize
class RegistryVocabulary(object):
"""vocabulary to use with plone.app.registry"""
interface.implements(IVocabularyFactory)
def __init__(self, key):
self.key = key
def __call__(self, context):
registry = component.queryUtility(IRegistry)
if registry is None:
return []
categories = registry[self.key]
terms = [SimpleTerm(baseNormalize(category),
baseNormalize(category),
category) for category in categories]
return SimpleVocabulary(terms)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment