src/pyams_skin/vocabulary.py
changeset 0 bb4aabe07487
child 155 cd3ab32436f0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_skin/vocabulary.py	Thu Feb 19 10:59:00 2015 +0100
@@ -0,0 +1,44 @@
+#
+# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
+# 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 interfaces
+from pyams_skin.interfaces import ISkin
+from zope.schema.interfaces import IVocabularyFactory
+
+# import packages
+from pyams_utils.request import check_request
+from zope.interface import provider
+from zope.componentvocabulary.vocabulary import UtilityVocabulary, UtilityTerm
+from zope.schema.vocabulary import getVocabularyRegistry
+
+
+@provider(IVocabularyFactory)
+class SkinsVocabulary(UtilityVocabulary):
+    "PyAMS skins vocabulary"""
+
+    interface = ISkin
+    nameOnly = True
+
+    def __init__(self, context, **kw):
+        request = check_request()
+        registry = request.registry
+        translate = request.localizer.translate
+        utils = [(name, translate(util.label, context=request))
+                 for (name, util) in registry.getUtilitiesFor(self.interface, context)]
+        self._terms = dict((title, UtilityTerm(name, title)) for name, title in utils)
+
+getVocabularyRegistry().register('PyAMS skins', SkinsVocabulary)