--- a/src/pyams_portal/template.py Wed May 23 15:09:07 2018 +0200
+++ b/src/pyams_portal/template.py Mon May 28 14:05:04 2018 +0200
@@ -19,7 +19,6 @@
from pyams_portal.interfaces import IPortalTemplateContainer, IPortalTemplateContainerConfiguration, \
IPortalTemplate, IPortalTemplateConfiguration, IPortalPortletsConfiguration, IPortlet, IPortletConfiguration, \
PORTLETS_CONFIGURATION_KEY, TEMPLATE_CONTAINER_CONFIGURATION_KEY, TEMPLATE_CONFIGURATION_KEY
-from zope.annotation.interfaces import IAnnotations
from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectRemovedEvent
from zope.traversing.interfaces import ITraversable
@@ -29,7 +28,7 @@
from persistent.mapping import PersistentMapping
from pyams_portal.portlet import PortalPortletsConfiguration
from pyams_portal.slot import SlotConfiguration
-from pyams_utils.adapter import adapter_config, ContextAdapter
+from pyams_utils.adapter import adapter_config, ContextAdapter, get_annotation_adapter
from pyams_utils.registry import get_local_registry, get_utility
from pyams_utils.request import check_request
from pyams_utils.vocabulary import vocabulary_config
@@ -38,9 +37,7 @@
from zope.componentvocabulary.vocabulary import UtilityVocabulary
from zope.container.contained import Contained
from zope.container.folder import Folder
-from zope.copy import clone
from zope.interface import implementer
-from zope.lifecycleevent import ObjectCreatedEvent
from zope.location import locate
from zope.schema.fieldproperty import FieldProperty
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
@@ -71,13 +68,7 @@
@adapter_config(context=IPortalTemplateContainer, provides=IPortalTemplateContainerConfiguration)
def portal_template_container_configuration_adapter(context):
"""Portal template container configuration factory"""
- annotations = IAnnotations(context)
- config = annotations.get(TEMPLATE_CONTAINER_CONFIGURATION_KEY)
- if config is None:
- config = annotations[TEMPLATE_CONTAINER_CONFIGURATION_KEY] = PortalTemplateContainerConfiguration()
- get_current_registry().notify(ObjectCreatedEvent(config))
- locate(config, context)
- return config
+ return get_annotation_adapter(context, TEMPLATE_CONTAINER_CONFIGURATION_KEY, PortalTemplateContainerConfiguration)
#
@@ -321,13 +312,7 @@
@adapter_config(context=IPortalTemplate, provides=IPortalTemplateConfiguration)
def portal_template_configuration_factory(context):
"""Portal template configuration adapter"""
- annotations = IAnnotations(context)
- config = annotations.get(TEMPLATE_CONFIGURATION_KEY)
- if config is None:
- config = annotations[TEMPLATE_CONFIGURATION_KEY] = PortalTemplateConfiguration()
- get_current_registry().notify(ObjectCreatedEvent(config))
- locate(config, context)
- return config
+ return get_annotation_adapter(context, TEMPLATE_CONFIGURATION_KEY, PortalTemplateConfiguration)
@adapter_config(name='portlet', context=IPortalTemplate, provides=ITraversable)
@@ -349,10 +334,4 @@
@adapter_config(context=IPortalTemplate, provides=IPortalPortletsConfiguration)
def portal_template_portlets_configuration_adapter(template):
"""Portal template portlets configuration adapter"""
- annotations = IAnnotations(template)
- config = annotations.get(PORTLETS_CONFIGURATION_KEY)
- if config is None:
- config = annotations[PORTLETS_CONFIGURATION_KEY] = PortalPortletsConfiguration()
- get_current_registry().notify(ObjectCreatedEvent(config))
- locate(config, template)
- return config
+ return get_annotation_adapter(template, PORTLETS_CONFIGURATION_KEY, PortalPortletsConfiguration)