|
1 # |
|
2 # Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net> |
|
3 # All Rights Reserved. |
|
4 # |
|
5 # This software is subject to the provisions of the Zope Public License, |
|
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. |
|
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
|
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
|
10 # FOR A PARTICULAR PURPOSE. |
|
11 # |
|
12 |
|
13 __docformat__ = 'restructuredtext' |
|
14 |
|
15 |
|
16 # import standard library |
|
17 |
|
18 # import interfaces |
|
19 from pyams_skin.interfaces import ISkin |
|
20 from zope.schema.interfaces import IVocabularyFactory |
|
21 |
|
22 # import packages |
|
23 from pyams_utils.request import check_request |
|
24 from zope.interface import provider |
|
25 from zope.componentvocabulary.vocabulary import UtilityVocabulary, UtilityTerm |
|
26 from zope.schema.vocabulary import getVocabularyRegistry |
|
27 |
|
28 |
|
29 @provider(IVocabularyFactory) |
|
30 class SkinsVocabulary(UtilityVocabulary): |
|
31 "PyAMS skins vocabulary""" |
|
32 |
|
33 interface = ISkin |
|
34 nameOnly = True |
|
35 |
|
36 def __init__(self, context, **kw): |
|
37 request = check_request() |
|
38 registry = request.registry |
|
39 translate = request.localizer.translate |
|
40 utils = [(name, translate(util.label, context=request)) |
|
41 for (name, util) in registry.getUtilitiesFor(self.interface, context)] |
|
42 self._terms = dict((title, UtilityTerm(name, title)) for name, title in utils) |
|
43 |
|
44 getVocabularyRegistry().register('PyAMS skins', SkinsVocabulary) |