src/pyams_content/component/paragraph/illustration.py
changeset 0 7c0001cacf8e
child 60 da1454d7d358
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/component/paragraph/illustration.py	Thu Oct 08 13:37:29 2015 +0200
@@ -0,0 +1,58 @@
+#
+# 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_content.component.paragraph.interfaces import IIllustrationParagraph, IIllustrationRenderer
+from zope.schema.interfaces import IVocabularyFactory
+
+# import packages
+from pyams_content.component.paragraph import BaseParagraph
+from pyams_file.property import FileProperty
+from pyams_utils.request import check_request
+from zope.interface import implementer, provider
+from zope.schema.fieldproperty import FieldProperty
+from zope.schema.vocabulary import getVocabularyRegistry, SimpleVocabulary, SimpleTerm
+
+
+#
+# Illustration
+#
+
+@implementer(IIllustrationParagraph)
+class Illustration(BaseParagraph):
+    """Illustration class"""
+
+    data = FileProperty(IIllustrationParagraph['data'])
+    legend = FieldProperty(IIllustrationParagraph['legend'])
+    renderer = FieldProperty(IIllustrationParagraph['renderer'])
+
+
+@provider(IVocabularyFactory)
+class IllustrationRendererVocabulary(SimpleVocabulary):
+    """Illustration renderer utilities vocabulary"""
+
+    def __init__(self, context=None):
+        request = check_request()
+        translate = request.localizer.translate
+        registry = request.registry
+        context = Illustration()
+        terms = [SimpleTerm(name, title=translate(adapter.label))
+                 for name, adapter in sorted(registry.getAdapters((context, request), IIllustrationRenderer),
+                                             key=lambda x: x[1].weight)]
+        super(IllustrationRendererVocabulary, self).__init__(terms)
+
+getVocabularyRegistry().register('PyAMS illustration renderers', IllustrationRendererVocabulary)