|
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_content.features.renderer.interfaces import IContentRenderer |
|
20 |
|
21 # import packages |
|
22 from pyams_content.component.illustration import Illustration, IIllustration |
|
23 from pyams_utils.request import check_request |
|
24 from pyams_utils.vocabulary import vocabulary_config |
|
25 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm |
|
26 |
|
27 |
|
28 @vocabulary_config(name='PyAMS illustration renderers') |
|
29 class IllustrationRendererVocabulary(SimpleVocabulary): |
|
30 """Illustration renderer utilities vocabulary""" |
|
31 |
|
32 def __init__(self, context=None): |
|
33 request = check_request() |
|
34 translate = request.localizer.translate |
|
35 registry = request.registry |
|
36 if not IIllustration.providedBy(context): |
|
37 context = Illustration() |
|
38 terms = [SimpleTerm(name, title=translate(adapter.label)) |
|
39 for name, adapter in sorted(registry.getAdapters((context, request), IContentRenderer), |
|
40 key=lambda x: x[1].weight)] |
|
41 super(IllustrationRendererVocabulary, self).__init__(terms) |