src/pyams_content/shared/logo/paragraph.py
changeset 438 117089568313
parent 407 0ef5de2d5674
child 555 8e8a14452567
--- a/src/pyams_content/shared/logo/paragraph.py	Fri Mar 02 17:36:12 2018 +0100
+++ b/src/pyams_content/shared/logo/paragraph.py	Fri Mar 02 17:54:01 2018 +0100
@@ -17,31 +17,36 @@
 
 # import interfaces
 from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE, ERROR_VALUE
-from pyams_content.shared.logo.interfaces import ILogosParagraph, LOGOS_PARAGRAPH_TYPE
+from pyams_content.shared.logo.interfaces import ILogosParagraph, LOGOS_PARAGRAPH_TYPE, LOGOS_PARAGRAPH_RENDERERS
 from pyams_i18n.interfaces import II18nManager, INegotiator, II18n
 from pyams_workflow.interfaces import IWorkflow, IWorkflowState
 
 # import packages
 from pyams_content.component.paragraph import BaseParagraph, IParagraphFactory, BaseParagraphFactory, \
     BaseParagraphContentChecker
+from pyams_content.features.renderer import RenderedContentMixin, IContentRenderer
 from pyams_sequence.utility import get_reference_target
 from pyams_utils.adapter import adapter_config
 from pyams_utils.registry import utility_config, get_utility
+from pyams_utils.request import check_request
 from pyams_utils.traversing import get_parent
+from pyams_utils.vocabulary import vocabulary_config
 from zope.interface import implementer
 from zope.schema.fieldproperty import FieldProperty
+from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
 
 from pyams_content import _
 
 
 @implementer(ILogosParagraph)
-class LogosParagraph(BaseParagraph):
+class LogosParagraph(RenderedContentMixin, BaseParagraph):
     """Logos paragraph"""
 
     icon_class = 'fa-th-large'
     icon_hint = _("Logos")
 
     references = FieldProperty(ILogosParagraph['references'])
+    renderer = FieldProperty(ILogosParagraph['renderer'])
 
     def get_targets(self, state=None, with_reference=False):
         for reference in self.references or ():
@@ -103,3 +108,19 @@
                                 message=translate(_("logo '{0}' is not published")).format(
                                     II18n(target).query_attribute('title', request=request))))
         return output
+
+
+@vocabulary_config(name=LOGOS_PARAGRAPH_RENDERERS)
+class LogosParagraphRendererVocabulary(SimpleVocabulary):
+    """Logos paragraph renderers vocabulary"""
+
+    def __init__(self, context=None):
+        request = check_request()
+        translate = request.localizer.translate
+        registry = request.registry
+        if not ILogosParagraph.providedBy(context):
+            context = LogosParagraph()
+        terms = [SimpleTerm(name, title=translate(adapter.label))
+                 for name, adapter in sorted(registry.getAdapters((context, request), IContentRenderer),
+                                             key=lambda x: x[1].weight)]
+        super(LogosParagraphRendererVocabulary, self).__init__(terms)