# HG changeset patch # User Thierry Florac # Date 1545908153 -3600 # Node ID 3a76d0bdc3c7d917bba3af619db6f69f45b6a1f6 # Parent 92a8197836dc067cc8dd6f1fd89bf193efdcf474 Added check in portal portlets configuration adapter diff -r 92a8197836dc -r 3a76d0bdc3c7 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)