# HG changeset patch # User Thierry Florac # Date 1437578668 -7200 # Node ID 5717572bf2a8ae3f106eb8a7c40487544493d4c5 # Parent 5f2f8657934bc3604c6c619d07017dca8b764c4c Added thesaurus context manager diff -r 5f2f8657934b -r 5717572bf2a8 src/pyams_thesaurus/interfaces/thesaurus.py --- a/src/pyams_thesaurus/interfaces/thesaurus.py Wed Jul 22 17:23:33 2015 +0200 +++ b/src/pyams_thesaurus/interfaces/thesaurus.py Wed Jul 22 17:24:28 2015 +0200 @@ -180,3 +180,21 @@ """Thesaurus extracts container interface""" contains(IThesaurusExtractInfo) + + +class IThesaurusContextManager(Interface): + """Thesaurus terms manager interface""" + + thesaurus_name = Choice(title=_("Thesaurus name"), + vocabulary='PyAMS thesaurus names', + required=False) + + extract_name = Choice(title=_("Thesaurus extract"), + vocabulary='PyAMS thesaurus extracts', + required=False) + + +class IThesaurusContextManagerTarget(Interface): + """Marker interface for tools managing thesaurus terms""" + + diff -r 5f2f8657934b -r 5717572bf2a8 src/pyams_thesaurus/thesaurus.py --- a/src/pyams_thesaurus/thesaurus.py Wed Jul 22 17:23:33 2015 +0200 +++ b/src/pyams_thesaurus/thesaurus.py Wed Jul 22 17:24:28 2015 +0200 @@ -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 + IThesaurusRoles, IThesaurusExtracts, IThesaurusContextManagerTarget, IThesaurusContextManager from pyams_utils.interfaces.site import IOptionalUtility from pyams_utils.interfaces.tree import ITree from transaction.interfaces import ITransactionManager @@ -376,6 +376,10 @@ terms = [] if context is not None: thesaurus = get_parent(context, IThesaurus) + if thesaurus is None: + context_manager = IThesaurusContextManager(context, None) + if context_manager is not None: + thesaurus = query_utility(IThesaurus, name=context_manager.thesaurus_name) if thesaurus is not None: extracts = IThesaurusExtracts(thesaurus) terms = [SimpleTerm(extract.__name__, title=extract.name) for extract in extracts.values()]