Created
August 14, 2012 15:43
-
-
Save toutpt/3350395 to your computer and use it in GitHub Desktop.
registry vocabulary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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