Added thesaurus context manager
authorThierry Florac <thierry.florac@onf.fr>
Wed, 22 Jul 2015 17:24:28 +0200
changeset 13 5717572bf2a8
parent 12 5f2f8657934b
child 14 2710a8dbfc97
Added thesaurus context manager
src/pyams_thesaurus/interfaces/thesaurus.py
src/pyams_thesaurus/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"""
+
+
--- 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()]