Use request header to store new thesaurus name
authorThierry Florac <tflorac@ulthar.net>
Fri, 22 Mar 2019 17:40:32 +0100
changeset 115 91b51d5e32e7
parent 114 e7e4b4146a91
child 116 f10973853d11
Use request header to store new thesaurus name
src/pyams_thesaurus/thesaurus.py
--- a/src/pyams_thesaurus/thesaurus.py	Fri Mar 22 15:23:35 2019 +0100
+++ b/src/pyams_thesaurus/thesaurus.py	Fri Mar 22 17:40:32 2019 +0100
@@ -369,11 +369,16 @@
     def __init__(self, context=None):
         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) and context_manager.thesaurus_name:
-                    thesaurus = query_utility(IThesaurus, name=context_manager.thesaurus_name)
+            request = check_request()
+            thesaurus_name = request.headers.get('X-Thesaurus-Name')
+            if thesaurus_name is not None:
+                thesaurus = query_utility(IThesaurus, name=thesaurus_name)
+            else:
+                thesaurus = get_parent(context, IThesaurus)
+                if thesaurus is None:
+                    context_manager = IThesaurusContextManager(context, None)
+                    if (context_manager is not None) and context_manager.thesaurus_name:
+                        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()]