From 9cfc4f66c4b7a619c9dc49cf58b400b4c44c99a3 Mon Sep 17 00:00:00 2001
From: Douglas Camata <douglas.camata@nexedi.com>
Date: Mon, 23 May 2016 21:59:43 +0200
Subject: [PATCH] pivottablejs: removed erp5_url parameter in favor of REQUEST
 headers

This is the proper way to refer to the URL on which ERP5 is being served.
---
 .../portal_components/extension.erp5.JupyterCompile.py     | 7 ++++---
 .../portal_components/test.erp5.testExecuteJupyter.py      | 3 ++-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterCompile.py b/bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterCompile.py
index 95970f6e69..21625a1edf 100644
--- a/bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterCompile.py
+++ b/bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterCompile.py
@@ -397,7 +397,7 @@ class ProcessorList(object):
       return self.processors.get(something.__class__, self.default_processor)
     else:
       return self.processors.get(something.__name__, self.default_processor)
-      
+
 
 def storeIFrame(self, html, key):
   self.portal_caches.erp5_pivottable_frame_cache.set(key, html)
@@ -408,7 +408,7 @@ def storeIFrame(self, html, key):
 # This is a highly experimental PivotTableJs integration which does not follow
 # ERP5 Javascrpt standards and it will be refactored to use JIO and RenderJS.
 #
-def erp5PivotTableUI(self, df, erp5_url):
+def erp5PivotTableUI(self, df):
   from IPython.display import IFrame
   template = """
   <!DOCTYPE html>
@@ -477,5 +477,6 @@ def erp5PivotTableUI(self, df, erp5_url):
   from hashlib import sha512
   key = sha512(html_string).hexdigest()
   storeIFrame(self, html_string, key)
-  url = "%s/Base_displayPivotTableFrame?key=%s" % (erp5_url, key)
+  iframe_host = self.REQUEST['HTTP_X_FORWARDED_HOST'].split(',')[0]
+  url = "https://%s/erp5/Base_displayPivotTableFrame?key=%s" % (iframe_host, key)
   return IFrame(src=url, width='100%', height='500')
diff --git a/bt5/erp5_data_notebook/TestTemplateItem/portal_components/test.erp5.testExecuteJupyter.py b/bt5/erp5_data_notebook/TestTemplateItem/portal_components/test.erp5.testExecuteJupyter.py
index 401094847c..fffb6bae0a 100644
--- a/bt5/erp5_data_notebook/TestTemplateItem/portal_components/test.erp5.testExecuteJupyter.py
+++ b/bt5/erp5_data_notebook/TestTemplateItem/portal_components/test.erp5.testExecuteJupyter.py
@@ -452,7 +452,7 @@ class DataFrameMock(object):
         return "column1, column2; 1, 2;" 
 
 my_df = DataFrameMock()
-iframe = context.Base_erp5PivotTableUI(my_df, 'https://localhost:2202/erp5')
+iframe = context.Base_erp5PivotTableUI(my_df)
 context.Base_renderAsHtml(iframe)
 '''
     reference = 'Test.Notebook.PivotTableJsIntegration %s' % time.time()
@@ -467,3 +467,4 @@ context.Base_renderAsHtml(iframe)
     # of the pivot table page's html.
     pivottable_frame_display_path = 'Base_displayPivotTableFrame?key=853524757258b19805d13beb8c6bd284a7af4a974a96a3e5a4847885df069a74d3c8c1843f2bcc4d4bb3c7089194b57c90c14fe8dd0c776d84ce0868e19ac411'
     self.assertTrue(pivottable_frame_display_path in json_result['code_result'])
+
-- 
2.30.9