# HG changeset patch # User Thierry Florac # Date 1547715694 -3600 # Node ID 06272e2e8bb5f7c673ce303ef21c0e20e55368cc # Parent 9149ffc59bb4ecf458bc54c67d57505fe380801a Use object factory in annotations adapters diff -r 9149ffc59bb4 -r 06272e2e8bb5 src/pyams_thesaurus/thesaurus.py --- a/src/pyams_thesaurus/thesaurus.py Wed Jan 09 12:20:26 2019 +0100 +++ b/src/pyams_thesaurus/thesaurus.py Thu Jan 17 10:01:34 2019 +0100 @@ -12,53 +12,50 @@ __docformat__ = 'restructuredtext' - -# import standard library import re -# import interfaces +from hypatia.catalog import Catalog +from hypatia.query import Contains, Eq +from hypatia.text.lexicon import Lexicon +from hypatia.text.parsetree import QueryError +from persistent import Persistent +from pyramid.events import subscriber +from transaction.interfaces import ITransactionManager +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.interface.interfaces import ComponentLookupError +from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectRemovedEvent +from zope.location import locate +from zope.location.interfaces import ISublocations +from zope.schema.fieldproperty import FieldProperty +from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary +from zope.traversing.interfaces import ITraversable + +from pyams_catalog.index import FieldIndexWithInterface, TextIndexWithInterface +from pyams_catalog.nltk import NltkStemmedTextProcessor +from pyams_catalog.query import CatalogResultSet, or_ +from pyams_catalog.utils import index_object from pyams_form.interfaces.form import IFormContextPermissionChecker from pyams_security.interfaces import IDefaultProtectionPolicy +from pyams_security.property import RolePrincipalsFieldProperty +from pyams_security.security import ProtectedObject from pyams_thesaurus.interfaces import ADMIN_THESAURUS_PERMISSION from pyams_thesaurus.interfaces.extension import IThesaurusTermExtension 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, IThesaurusContextManager +from pyams_thesaurus.interfaces.term import IThesaurusLoaderTerm, IThesaurusTerm, IThesaurusTermsContainer +from pyams_thesaurus.interfaces.thesaurus import IThesaurus, IThesaurusContextManager, IThesaurusExtract, \ + IThesaurusExtractRoles, IThesaurusExtracts, IThesaurusRoles +from pyams_utils.adapter import ContextAdapter, adapter_config, get_annotation_adapter +from pyams_utils.factory import factory_config from pyams_utils.interfaces.site import IOptionalUtility from pyams_utils.interfaces.tree import ITree -from transaction.interfaces import ITransactionManager -from zope.interface.interfaces import ComponentLookupError -from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectRemovedEvent -from zope.location.interfaces import ISublocations -from zope.traversing.interfaces import ITraversable - -# import packages -from hypatia.catalog import Catalog -from hypatia.query import Eq, Contains -from hypatia.text.lexicon import Lexicon -from hypatia.text.parsetree import QueryError -from persistent import Persistent -from pyams_catalog.index import TextIndexWithInterface, FieldIndexWithInterface -from pyams_catalog.nltk import NltkStemmedTextProcessor -from pyams_catalog.query import CatalogResultSet, or_ -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, get_annotation_adapter -from pyams_utils.registry import query_utility, get_utilities_for, get_global_registry +from pyams_utils.registry import get_global_registry, query_utility 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 zope.componentvocabulary.vocabulary import UtilityVocabulary -from zope.container.btree import BTreeContainer -from zope.container.contained import Contained -from zope.interface import implementer -from zope.location import locate -from zope.schema.fieldproperty import FieldProperty -from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm CUSTOM_SEARCH = re.compile(r'\*|\"|\sand\s|\sor\s|\snot\s|\(|\)', re.IGNORECASE) @@ -291,7 +288,7 @@ THESAURUS_EXTRACTS_KEY = 'pyams_thesaurus.extracts' -@implementer(IThesaurusExtracts) +@factory_config(IThesaurusExtracts) class ThesaurusExtractsContainer(BTreeContainer): """Thesaurus extracts container""" @@ -299,7 +296,7 @@ @adapter_config(context=IThesaurus, provides=IThesaurusExtracts) def thesaurus_extracts_factory(context): """Thesaurus extracts factory""" - return get_annotation_adapter(context, THESAURUS_EXTRACTS_KEY, ThesaurusExtractsContainer, + return get_annotation_adapter(context, THESAURUS_EXTRACTS_KEY, IThesaurusExtracts, name='++extracts++')