Changed vocabulary declaration
authorThierry Florac <thierry.florac@onf.fr>
Tue, 15 Nov 2016 10:41:35 +0100
changeset 23 9885b9c88b2e
parent 22 9f1ca1ad2a12
child 24 e1a86d99c7d4
Changed vocabulary declaration
src/pyams_thesaurus/loader/__init__.py
src/pyams_thesaurus/thesaurus.py
--- a/src/pyams_thesaurus/loader/__init__.py	Tue Oct 11 16:15:05 2016 +0200
+++ b/src/pyams_thesaurus/loader/__init__.py	Tue Nov 15 10:41:35 2016 +0100
@@ -22,7 +22,6 @@
     IThesaurusExporter
 from pyams_thesaurus.interfaces.term import IThesaurusLoaderTerm
 from pyams_thesaurus.interfaces.thesaurus import IThesaurusDescription
-from zope.schema.interfaces import IVocabularyFactory
 
 # import packages
 from BTrees.OOBTree import OOBTree
@@ -30,10 +29,10 @@
 from pyams_thesaurus.thesaurus import ThesaurusTermsContainer, Thesaurus
 from pyams_utils.request import query_request
 from pyams_utils.unicode import translate_string
+from pyams_utils.vocabulary import vocabulary_config
 from zope.componentvocabulary.vocabulary import UtilityVocabulary
-from zope.interface import implementer, provider, alsoProvides, noLongerProvides
+from zope.interface import implementer, alsoProvides, noLongerProvides
 from zope.schema.fieldproperty import FieldProperty
-from zope.schema.vocabulary import getVocabularyRegistry
 
 
 #
@@ -172,15 +171,13 @@
         return Thesaurus(description=description, terms=store)
 
 
-@provider(IVocabularyFactory)
+@vocabulary_config(name='PyAMS thesaurus loaders')
 class ThesaurusLoadersVocabulary(UtilityVocabulary):
     """Thesaurus loaders vocabulary"""
 
     interface = IThesaurusLoader
     nameOnly = True
 
-getVocabularyRegistry().register('PyAMS thesaurus loaders', ThesaurusLoadersVocabulary)
-
 
 #
 # Thesaurus exporters classes
@@ -229,11 +226,9 @@
         return output
 
 
-@provider(IVocabularyFactory)
+@vocabulary_config(name='PyAMS thesaurus exporters')
 class ThesaurusExportersVocabulary(UtilityVocabulary):
     """Thesaurus exporters vocabulary"""
 
     interface = IThesaurusExporter
     nameOnly = True
-
-getVocabularyRegistry().register('PyAMS thesaurus exporters', ThesaurusExportersVocabulary)
--- 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)