--- a/src/pyams_portal/interfaces/__init__.py Wed Jun 28 10:16:27 2017 +0200
+++ b/src/pyams_portal/interfaces/__init__.py Wed Jun 28 11:45:31 2017 +0200
@@ -152,6 +152,8 @@
label = Attribute("Renderer name")
+ target_interface = Attribute("Target interface provided by this renderer")
+
class IPortalPortletsConfiguration(IContained):
"""Portal template portlet configuration interface"""
--- a/src/pyams_portal/portlet.py Wed Jun 28 10:16:27 2017 +0200
+++ b/src/pyams_portal/portlet.py Wed Jun 28 11:45:31 2017 +0200
@@ -36,7 +36,7 @@
from pyramid.threadlocal import get_current_registry
from zope.container.contained import Contained
from zope.copy import clone
-from zope.interface import implementer
+from zope.interface import implementer, alsoProvides, noLongerProvides
from zope.lifecycleevent import ObjectCreatedEvent
from zope.location import locate
from zope.schema.fieldproperty import FieldProperty
@@ -160,6 +160,8 @@
class PortletRenderer(PortletContentProvider):
"""Portlet renderer adapter"""
+ target_interface = None
+
@property
def slot_configuration(self):
template = IPortalPage(self.context).template
@@ -190,7 +192,7 @@
"""Portlet settings persistent class"""
visible = FieldProperty(IPortletSettings['visible'])
- renderer = FieldProperty(IPortletSettings['renderer'])
+ _renderer = FieldProperty(IPortletSettings['renderer'])
__name__ = '++settings++'
@@ -198,6 +200,26 @@
self.__parent__ = configuration
@property
+ def renderer(self):
+ return self._renderer
+
+ @renderer.setter
+ def renderer(self, value):
+ value = value or ''
+ if value == self._renderer:
+ return
+ request = check_request()
+ renderer = request.registry.queryMultiAdapter((request.root, request, request, self), IPortletRenderer,
+ name=self._renderer)
+ if (renderer is not None) and (renderer.target_interface is not None):
+ noLongerProvides(self, renderer.target_interface)
+ self._renderer = value
+ renderer = request.registry.queryMultiAdapter((request.root, request, request, self), IPortletRenderer,
+ name=self._renderer)
+ if (renderer is not None) and (renderer.target_interface is not None):
+ alsoProvides(self, renderer.target_interface)
+
+ @property
def configuration(self):
return self.__parent__