Commit a1c44246 authored by Iliya Manolov's avatar Iliya Manolov Committed by Eteri

Added a warning about using old references on Jupyter notebooks

@Tyagov @luke 

See the MR at slapos [here](nexedi/slapos!177).

/reviewed-on nexedi/erp5!283
parent 325bb3c7
......@@ -867,9 +867,6 @@ class ImportFixer(ast.NodeTransformer):
if not self.import_func_dict.get(name):
final_module_names.append(name)
log("module_names[0]: " + module_names[0])
log("result_name: " + result_name)
if final_module_names:
# try to import module before it is added to environment
# this way if user tries to import non existent module Exception
......@@ -879,8 +876,6 @@ class ImportFixer(ast.NodeTransformer):
empty_function = self.newEmptyFunction("%s_setup" %result_name)
return_dict = self.newReturnDict(final_module_names)
log(return_dict)
empty_function.body = [node, return_dict]
environment_set = self.newEnvironmentSetCall("%s_setup" %result_name)
warning = self.newImportWarningCall(root_module_name, result_name)
......@@ -1180,3 +1175,12 @@ def erp5PivotTableUI(self, df):
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')
def Base_checkExistingReference(self, reference):
existing_notebook = self.portal_catalog.getResultValue(
owner=self.portal_membership.getAuthenticatedMember().getUserName(),
portal_type='Data Notebook',
reference=reference)
if not existing_notebook is None:
return True
return False
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_function</string> </key>
<value> <string>Base_checkExistingReference</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>JupyterCompile</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_checkExistingReference</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -32,6 +32,8 @@ from Products.ERP5Type.tests.utils import createZODBPythonScript, removeZODBPyth
import time
import json
import base64
import random
import string
class TestExecuteJupyter(ERP5TypeTestCase):
......@@ -857,3 +859,25 @@ print dig
self.assertEquals(result['status'], 'ok')
self.assertEquals(result['code_result'].strip(), '0123456789')
def testReferenceWarning(self):
'''
Tests Base_checkExistingReference in JupyterCompile.
'''
self.login('dev_user')
notebook_reference = u''.join(random.choice(string.ascii_lowercase) for _ in range(30))
notebook_title = u''.join(random.choice(string.ascii_lowercase) for _ in range(30))
notebook_module = self.portal.getDefaultModule(portal_type='Data Notebook')
data_notebook = notebook_module.DataNotebookModule_addDataNotebook(
title=notebook_title,
reference=notebook_reference,
batch_mode=True)
self.tic()
result = self.portal.Base_checkExistingReference(
reference=notebook_reference,
)
self.tic()
self.assertEquals(result, True)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment