Added check in portal portlets configuration adapter
authorThierry Florac <tflorac@ulthar.net>
Thu, 27 Dec 2018 11:55:53 +0100
changeset 245 3a76d0bdc3c7
parent 244 92a8197836dc
child 246 b2c7a305843b
Added check in portal portlets configuration adapter
src/pyams_portal/page.py
--- a/src/pyams_portal/page.py	Fri Dec 21 20:11:48 2018 +0100
+++ b/src/pyams_portal/page.py	Thu Dec 27 11:55:53 2018 +0100
@@ -15,26 +15,25 @@
 
 # import standard library
 
-# import interfaces
-from pyams_portal.interfaces import IPortalPage, IPortalContext, IPortalTemplateConfiguration, \
-    IPortalTemplate, PORTAL_PAGE_KEY, IPortalPortletsConfiguration, PORTLETS_CONFIGURATION_KEY, \
-    ILocalTemplateHandler, LOCAL_TEMPLATE_NAME
-from zope.traversing.interfaces import ITraversable
-
 # import packages
 from persistent import Persistent
-from pyams_portal.portlet import PortalPortletsConfiguration
-from pyams_portal.template import PortalTemplate
-from pyams_utils.adapter import adapter_config, ContextAdapter, get_annotation_adapter
-from pyams_utils.registry import query_utility
-from pyams_utils.zodb import volatile_property
 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 alsoProvides, implementer, noLongerProvides
 from zope.lifecycleevent import ObjectCreatedEvent
 from zope.location import locate
 from zope.schema.fieldproperty import FieldProperty
+from zope.traversing.interfaces import ITraversable
+
+# import interfaces
+from pyams_portal.interfaces import ILocalTemplateHandler, IPortalContext, IPortalPage, IPortalPortletsConfiguration, \
+    IPortalTemplate, IPortalTemplateConfiguration, LOCAL_TEMPLATE_NAME, PORTAL_PAGE_KEY, PORTLETS_CONFIGURATION_KEY
+from pyams_portal.portlet import PortalPortletsConfiguration
+from pyams_portal.template import PortalTemplate
+from pyams_utils.adapter import ContextAdapter, adapter_config, get_annotation_adapter
+from pyams_utils.registry import query_utility
+from pyams_utils.zodb import volatile_property
 
 
 @implementer(IPortalPage)
@@ -170,18 +169,19 @@
         template = page.local_template
     else:
         template = page.template
-    portlets_config = IPortalPortletsConfiguration(template)
-    if page.use_local_template:
-        context = template
-    # get current configuration
-    config = get_annotation_adapter(context, PORTLETS_CONFIGURATION_KEY,
-                                    factory=portlet_configuration_factory,
-                                    notify=False, locate=False)
-    # check for missing portlets configuration
-    for portlet_id, portlet_config in portlets_config.items():
-        if portlet_id not in config:
-            config.set_portlet_configuration(portlet_id, clone(portlet_config))
-    return config
+    if template is not None:
+        portlets_config = IPortalPortletsConfiguration(template)
+        if page.use_local_template:
+            context = template
+        # get current configuration
+        config = get_annotation_adapter(context, PORTLETS_CONFIGURATION_KEY,
+                                        factory=portlet_configuration_factory,
+                                        notify=False, locate=False)
+        # check for missing portlets configuration
+        for portlet_id, portlet_config in portlets_config.items():
+            if portlet_id not in config:
+                config.set_portlet_configuration(portlet_id, clone(portlet_config))
+        return config
 
 
 @adapter_config(name='portlet', context=IPortalContext, provides=ITraversable)