# HG changeset patch # User Thierry Florac # Date 1479202983 -3600 # Node ID ba0aefcd471a58c374c1918498e4269b40d49897 # Parent 0b859bda300e9fa2e67d603e81bdc7b117cb9ff7 Added annotation for vocabulary registry diff -r 0b859bda300e -r ba0aefcd471a src/pyams_utils/vocabulary.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_utils/vocabulary.py Tue Nov 15 10:43:03 2016 +0100 @@ -0,0 +1,38 @@ +# +# Copyright (c) 2008-2015 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +__docformat__ = 'restructuredtext' + + +# import standard library +import logging +logger = logging.getLogger('PyAMS (utils)') + +# import interfaces +from zope.schema.interfaces import IVocabularyFactory + +# import packages +from zope.interface import directlyProvides +from zope.schema.vocabulary import getVocabularyRegistry + + +class vocabulary_config: + """Class decorator to define a vocabulary""" + + def __init__(self, name): + self.name = name + + def __call__(self, klass): + logger.debug('Registering class {0} as vocabulary with name "{1}"'.format(str(klass), self.name)) + directlyProvides(klass, IVocabularyFactory) + getVocabularyRegistry().register(self.name, klass) + return klass