Updated annotations adapter
authorThierry Florac <thierry.florac@onf.fr>
Mon, 28 May 2018 09:53:33 +0200
changeset 41 5d273277716b
parent 40 56701baa79ee
child 42 6b7548af679d
Updated annotations adapter
src/pyams_gis/configuration.py
--- a/src/pyams_gis/configuration.py	Mon May 28 09:52:24 2018 +0200
+++ b/src/pyams_gis/configuration.py	Mon May 28 09:53:33 2018 +0200
@@ -17,16 +17,12 @@
 
 # import interfaces
 from pyams_gis.interfaces.configuration import IMapConfiguration, IMapConfigurationTarget
-from zope.annotation.interfaces import IAnnotations
 
 # import packages
 from persistent import Persistent
-from pyams_utils.adapter import adapter_config
-from pyramid.threadlocal import get_current_registry
+from pyams_utils.adapter import adapter_config, get_annotation_adapter
 from zope.container.contained import Contained
 from zope.interface import implementer
-from zope.lifecycleevent import ObjectCreatedEvent
-from zope.location import locate
 from zope.schema.fieldproperty import FieldProperty
 
 
@@ -86,10 +82,4 @@
 @adapter_config(context=IMapConfigurationTarget, provides=IMapConfiguration)
 def map_configuration_factory(context):
     """Map configuration factory"""
-    annotations = IAnnotations(context)
-    configuration = annotations.get(MAP_CONFIGURATION_KEY)
-    if configuration is None:
-        configuration = annotations[MAP_CONFIGURATION_KEY] = MapConfiguration()
-        get_current_registry().notify(ObjectCreatedEvent(configuration))
-        locate(configuration, context)
-    return configuration
+    return get_annotation_adapter(context, MAP_CONFIGURATION_KEY, MapConfiguration)