Added portlet renderers vocabulary
authorThierry Florac <thierry.florac@onf.fr>
Wed, 28 Jun 2017 10:14:07 +0200
changeset 30 1e3f8a25ab06
parent 29 3002631ab3b7
child 31 aa6d07b1fab1
Added portlet renderers vocabulary
src/pyams_portal/portlet.py
--- a/src/pyams_portal/portlet.py	Wed Jun 28 10:13:17 2017 +0200
+++ b/src/pyams_portal/portlet.py	Wed Jun 28 10:14:07 2017 +0200
@@ -21,7 +21,8 @@
 
 # import interfaces
 from pyams_portal.interfaces import IPortlet, IPortletSettings, IPortletConfiguration, IPortletPreviewer, \
-    IPortletRenderer, IPortalPortletsConfiguration, IPortalTemplate, IPortalContext, IPortalPage
+    IPortletRenderer, IPortalPortletsConfiguration, IPortalTemplate, IPortalContext, IPortalPage, \
+    IPortalTemplateConfiguration
 from zope.traversing.interfaces import ITraversable
 
 # import packages
@@ -144,11 +145,41 @@
 class PortletPreviewer(PortletContentProvider):
     """Portlet previewer adapter"""
 
+    @property
+    def slot_configuration(self):
+        if IPortalTemplate.providedBy(self.context):
+            template = self.context
+        else:
+            template = IPortalPage(self.context).template
+        config = IPortalTemplateConfiguration(template)
+        slot_id, slot_name = config.get_portlet_slot(self.settings.configuration.portlet_id)
+        return config.get_slot_configuration(slot_name)
+
 
 @implementer(IPortletRenderer)
 class PortletRenderer(PortletContentProvider):
     """Portlet renderer adapter"""
 
+    @property
+    def slot_configuration(self):
+        template = IPortalPage(self.context).template
+        config = IPortalTemplateConfiguration(template)
+        slot_id, slot_name = config.get_portlet_slot(self.settings.configuration.portlet_id)
+        return config.get_slot_configuration(slot_name)
+
+
+@vocabulary_config(name='PyAMS portlet renderers')
+class PortletRenderersVocabulary(SimpleVocabulary):
+    """Portlet renderers vocabulary"""
+
+    def __init__(self, context):
+        request = check_request()
+        translate = request.localizer.translate
+        terms = [SimpleTerm(name, title=translate(adapter.label))
+                 for name, adapter in request.registry.getAdapters((request.root, request, request, context),
+                                                                   IPortletRenderer)]
+        super(PortletRenderersVocabulary, self).__init__(terms)
+
 
 #
 # Portlet configuration
@@ -159,6 +190,7 @@
     """Portlet settings persistent class"""
 
     visible = FieldProperty(IPortletSettings['visible'])
+    renderer = FieldProperty(IPortletSettings['renderer'])
 
     __name__ = '++settings++'