Updated associations container factory
authorThierry Florac <thierry.florac@onf.fr>
Fri, 18 May 2018 15:52:22 +0200
changeset 548 43048fb84b87
parent 547 5eb6713c8e7d
child 549 7340e6c1429f
Updated associations container factory
src/pyams_content/component/association/container.py
--- a/src/pyams_content/component/association/container.py	Fri May 18 15:51:58 2018 +0200
+++ b/src/pyams_content/component/association/container.py	Fri May 18 15:52:22 2018 +0200
@@ -19,20 +19,18 @@
 from pyams_content.component.association.interfaces import IAssociationContainer, IAssociationTarget, \
     ASSOCIATION_CONTAINER_KEY, IAssociationItem, IAssociationInfo
 from pyams_content.features.checker.interfaces import IContentChecker
-from zope.annotation.interfaces import IAnnotations
 from zope.location.interfaces import ISublocations
 from zope.traversing.interfaces import ITraversable
 
 # import packages
 from pyams_catalog.utils import index_object
 from pyams_content.features.checker import BaseContentChecker
-from pyams_utils.adapter import adapter_config, ContextAdapter
+from pyams_utils.adapter import adapter_config, get_annotation_adapter, ContextAdapter
+from pyams_utils.registry import get_current_registry
 from pyams_utils.traversing import get_parent
 from pyams_utils.vocabulary import vocabulary_config
-from pyramid.threadlocal import get_current_registry
 from zope.container.ordered import OrderedContainer
 from zope.interface import implementer
-from zope.lifecycleevent import ObjectCreatedEvent
 from zope.location import locate
 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
 
@@ -63,13 +61,7 @@
 @adapter_config(context=IAssociationTarget, provides=IAssociationContainer)
 def association_container_factory(target):
     """Associations container factory"""
-    annotations = IAnnotations(target)
-    container = annotations.get(ASSOCIATION_CONTAINER_KEY)
-    if container is None:
-        container = annotations[ASSOCIATION_CONTAINER_KEY] = AssociationContainer()
-        get_current_registry().notify(ObjectCreatedEvent(container))
-        locate(container, target, '++ass++')
-    return container
+    return get_annotation_adapter(target, ASSOCIATION_CONTAINER_KEY, AssociationContainer, name='++ass++')
 
 
 @adapter_config(name='ass', context=IAssociationTarget, provides=ITraversable)
@@ -77,7 +69,8 @@
     """Associations container ++ass++ namespace"""
 
     def traverse(self, name, furtherpath=None):
-        return IAssociationContainer(self.context)
+        registry = get_current_registry()
+        return registry.queryAdapter(self.context, IAssociationContainer, name=name or '')
 
 
 @adapter_config(name='associations', context=IAssociationTarget, provides=ISublocations)