src/pyams_thesaurus/thesaurus.py
changeset 23 9885b9c88b2e
parent 13 5717572bf2a8
child 30 1731fb6afaaf
--- a/src/pyams_thesaurus/thesaurus.py	Tue Oct 11 16:15:05 2016 +0200
+++ b/src/pyams_thesaurus/thesaurus.py	Tue Nov 15 10:41:35 2016 +0100
@@ -22,7 +22,7 @@
 from pyams_thesaurus.interfaces.loader import IThesaurusLoader
 from pyams_thesaurus.interfaces.term import IThesaurusTermsContainer, IThesaurusTerm, IThesaurusLoaderTerm
 from pyams_thesaurus.interfaces.thesaurus import IThesaurus, IThesaurusExtract, IThesaurusExtractRoles, \
-    IThesaurusRoles, IThesaurusExtracts, IThesaurusContextManagerTarget, IThesaurusContextManager
+    IThesaurusRoles, IThesaurusExtracts, IThesaurusContextManager
 from pyams_utils.interfaces.site import IOptionalUtility
 from pyams_utils.interfaces.tree import ITree
 from transaction.interfaces import ITransactionManager
@@ -30,7 +30,6 @@
 from zope.interface.interfaces import ComponentLookupError
 from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectRemovedEvent
 from zope.location.interfaces import ISublocations
-from zope.schema.interfaces import IVocabularyFactory
 from zope.traversing.interfaces import ITraversable
 
 # import packages
@@ -50,16 +49,17 @@
 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, provider
+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 getVocabularyRegistry, SimpleVocabulary, SimpleTerm
+from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
 
 
 CUSTOM_SEARCH = re.compile(r'\*|\"|\sand\s|\sor\s|\snot\s|\(|\)', re.IGNORECASE)
@@ -348,27 +348,23 @@
 # Vocabularies
 #
 
-@provider(IVocabularyFactory)
+@vocabulary_config(name='PyAMS thesaurus')
 class ThesaurusVocabulary(UtilityVocabulary):
     """Thesaurus utilities vocabulary"""
 
     interface = IThesaurus
     nameOnly = False
 
-getVocabularyRegistry().register('PyAMS thesaurus', ThesaurusVocabulary)
 
-
-@provider(IVocabularyFactory)
+@vocabulary_config(name='PyAMS thesaurus names')
 class ThesaurusNamesVocabulary(UtilityVocabulary):
     """Thesaurus names utilities vocabulary"""
 
     interface = IThesaurus
     nameOnly = True
 
-getVocabularyRegistry().register('PyAMS thesaurus names', ThesaurusNamesVocabulary)
 
-
-@provider(IVocabularyFactory)
+@vocabulary_config(name='PyAMS thesaurus extracts')
 class ThesaurusExtractsVocabulary(SimpleVocabulary):
     """Thesaurus extracts vocabulary"""
 
@@ -386,10 +382,8 @@
                 terms.sort(key=lambda x: x.title)
         super(ThesaurusExtractsVocabulary, self).__init__(terms)
 
-getVocabularyRegistry().register('PyAMS thesaurus extracts', ThesaurusExtractsVocabulary)
 
-
-@provider(IVocabularyFactory)
+@vocabulary_config(name='PyAMS thesaurus extensions')
 class ThesaurusTermExtensionsVocabulary(SimpleVocabulary):
     """Thesaurus term extensions vocabulary"""
 
@@ -403,5 +397,3 @@
         except ComponentLookupError:
             terms = []
         super(ThesaurusTermExtensionsVocabulary, self).__init__(terms)
-
-getVocabularyRegistry().register('PyAMS thesaurus extensions', ThesaurusTermExtensionsVocabulary)