Updated annotations adapters
authorThierry Florac <thierry.florac@onf.fr>
Mon, 28 May 2018 14:07:46 +0200
changeset 69 314c5b71bb85
parent 68 27ca00d70a54
child 70 16c0aaa78558
Updated annotations adapters
src/pyams_zmi/configuration.py
--- a/src/pyams_zmi/configuration.py	Wed May 23 15:25:13 2018 +0200
+++ b/src/pyams_zmi/configuration.py	Mon May 28 14:07:46 2018 +0200
@@ -20,16 +20,13 @@
 from pyams_utils.interfaces.site import ISiteRoot
 from pyams_utils.interfaces.tales import ITALESExtension
 from pyams_zmi.interfaces import IZMIConfiguration
-from pyams_zmi.layer import IAdminLayer
-from zope.annotation.interfaces import IAnnotations
 
 # import packages
 from persistent import Persistent
-from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter
+from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter, get_annotation_adapter
 from pyams_utils.traversing import get_parent
 from zope.container.contained import Contained
 from zope.interface import implementer, Interface
-from zope.location import locate
 from zope.schema.fieldproperty import FieldProperty
 
 
@@ -93,12 +90,8 @@
 @adapter_config(context=ISiteRoot, provides=IZMIConfiguration)
 def zmi_configuration_factory(context):
     """ZMI configuration factory"""
-    annotations = IAnnotations(context)
-    configuration = annotations.get(ZMI_CONFIGURATION_KEY)
-    if configuration is None:
-        configuration = annotations[ZMI_CONFIGURATION_KEY] = ZMIConfiguration()
-        locate(configuration, context)
-    return configuration
+    return get_annotation_adapter(context, ZMI_CONFIGURATION_KEY, ZMIConfiguration,
+                                  notify=False)
 
 
 @adapter_config(name='zmi_configuration', context=(Interface, Interface, Interface), provides=ITALESExtension)