--- a/src/pyams_portal/portlet.py Thu Jun 14 17:35:36 2018 +0200
+++ b/src/pyams_portal/portlet.py Fri Jun 15 14:05:17 2018 +0200
@@ -19,6 +19,8 @@
import venusian
+from inspect import isclass
+
# import interfaces
from pyams_form.interfaces.form import IFormContextPermissionChecker
from pyams_portal.interfaces import IPortlet, IPortletSettings, IPortletConfiguration, IPortletPreviewer, \
@@ -30,6 +32,7 @@
from persistent import Persistent
from persistent.mapping import PersistentMapping
from pyams_utils.adapter import adapter_config, ContextAdapter, get_adapter_weight, get_annotation_adapter
+from pyams_utils.factory import get_object_factory
from pyams_utils.request import check_request
from pyams_utils.vocabulary import vocabulary_config
from pyams_viewlet.viewlet import ViewContentProvider
@@ -38,7 +41,7 @@
from pyramid.threadlocal import get_current_registry
from zope.container.contained import Contained
from zope.copy import clone
-from zope.interface import implementer, alsoProvides, noLongerProvides
+from zope.interface import implementer, alsoProvides, noLongerProvides, Interface
from zope.lifecycleevent import ObjectCreatedEvent
from zope.location import locate
from zope.schema.fieldproperty import FieldProperty
@@ -58,7 +61,7 @@
toolbar_image = None
toolbar_css_class = 'fa fa-fw fa-2x fa-edit'
- settings_class = None
+ settings_factory = None
class portlet_config(object):
@@ -206,7 +209,10 @@
This class is supposed to be sub-classed by all custom portlet subclasses to
store their configuration settings.
- Each portlet sub-class must define it's settings class in it's "settings_class" attribute.
+
+ Each portlet sub-class must define it's settings factory in it's "settings_factory" attribute.
+ Given factory can be a function, a class or an interface; in this last case, implementation
+ is looking for default object factory registered for this interface.
"""
_renderer = FieldProperty(IPortletSettings['renderer'])
@@ -278,7 +284,11 @@
def __init__(self, portlet):
self.portlet_name = portlet.name
- self._settings = portlet.settings_class(self)
+ factory = portlet.settings_factory
+ if isclass(factory) and issubclass(factory, Interface):
+ factory = get_object_factory(factory)
+ assert factory is not None, "Missing portlet settings factory"
+ self._settings = factory(self)
@property
def can_inherit(self):