Updated annotations adapters
authorThierry Florac <thierry.florac@onf.fr>
Mon, 28 May 2018 14:06:50 +0200
changeset 61 5e05ea2cea51
parent 60 55b9eb802e08
child 62 5c7fe5a68736
Updated annotations adapters
src/pyams_thesaurus/thesaurus.py
--- a/src/pyams_thesaurus/thesaurus.py	Mon May 28 12:35:15 2018 +0200
+++ b/src/pyams_thesaurus/thesaurus.py	Mon May 28 14:06:50 2018 +0200
@@ -28,7 +28,6 @@
 from pyams_utils.interfaces.site import IOptionalUtility
 from pyams_utils.interfaces.tree import ITree
 from transaction.interfaces import ITransactionManager
-from zope.annotation.interfaces import IAnnotations
 from zope.interface.interfaces import ComponentLookupError
 from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectRemovedEvent
 from zope.location.interfaces import ISublocations
@@ -46,19 +45,17 @@
 from pyams_catalog.utils import index_object
 from pyams_security.security import ProtectedObject
 from pyams_security.property import RolePrincipalsFieldProperty
-from pyams_utils.adapter import adapter_config, ContextAdapter
+from pyams_utils.adapter import adapter_config, ContextAdapter, get_annotation_adapter
 from pyams_utils.registry import query_utility, get_utilities_for
 from pyams_utils.request import check_request
 from pyams_utils.traversing import get_parent
 from pyams_utils.unicode import translate_string
 from pyams_utils.vocabulary import vocabulary_config
 from pyramid.events import subscriber
-from pyramid.threadlocal import get_current_registry
 from zope.componentvocabulary.vocabulary import UtilityVocabulary
 from zope.container.btree import BTreeContainer
 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
 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
@@ -302,13 +299,8 @@
 @adapter_config(context=IThesaurus, provides=IThesaurusExtracts)
 def thesaurus_extracts_factory(context):
     """Thesaurus extracts factory"""
-    annotations = IAnnotations(context)
-    extracts = annotations.get(THESAURUS_EXTRACTS_KEY)
-    if extracts is None:
-        extracts = annotations[THESAURUS_EXTRACTS_KEY] = ThesaurusExtractsContainer()
-        get_current_registry().notify(ObjectCreatedEvent(extracts))
-        locate(extracts, context, '++extracts++')
-    return extracts
+    return get_annotation_adapter(context, THESAURUS_EXTRACTS_KEY, ThesaurusExtractsContainer,
+                                  name='++extracts++')
 
 
 @adapter_config(name='extracts', context=IThesaurus, provides=ITraversable)