Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yusei Tahara
erp5
Commits
bb3fe819
Commit
bb3fe819
authored
Oct 03, 2015
by
Ayush Tiwari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_data_notebook: Add comments and description for Base_executeJupyter python script
parent
ae9a5ccb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
9 deletions
+32
-9
bt5/erp5_data_notebook/SkinTemplateItem/portal_skins/erp5_data_notebook/Base_executeJupyter.xml
...m/portal_skins/erp5_data_notebook/Base_executeJupyter.xml
+32
-9
No files found.
bt5/erp5_data_notebook/SkinTemplateItem/portal_skins/erp5_data_notebook/Base_executeJupyter.xml
View file @
bb3fe819
...
@@ -61,15 +61,29 @@
...
@@ -61,15 +61,29 @@
</item>
</item>
<item>
<item>
<key>
<string>
_body
</string>
</key>
<key>
<string>
_body
</string>
</key>
<value>
<string>
portal = context.getPortalObject()\n
<value>
<string>
"""\n
# Check permissions for current user \n
Python script to create Data Notebook or update existing Data Notebooks\n
identifying notebook by reference from user.\n
\n
Expected behaviour from this script:-\n
1. Return unauthorized message for non-developer user.\n
2. Create new \'Data Notebook\' for new reference.\n
3. Add new \'Data Notebook Message\'to the existing Data Notebook on basis of reference.\n
4. Return python dictionary containing list of all notebooks for \'request_reference=True\'\n
"""\n
\n
portal = context.getPortalObject()\n
# Check permissions for current user and display message to non-authorized user \n
if not portal.Base_checkPermission(\'portal_components\', \'Manage Portal\'):\n
if not portal.Base_checkPermission(\'portal_components\', \'Manage Portal\'):\n
return "You are not authorized to access the script"\n
return "You are not authorized to access the script"\n
\n
\n
import json\n
import json\n
\n
\n
#
The boolean values via requests are received as
\n
#
Convert the request_reference argument string to their respeced boolean values
\n
request_reference = {\'True\': True, \'False\': False}.get(request_reference, False)\n
request_reference = {\'True\': True, \'False\': False}.get(request_reference, False)\n
\n
# Return python dictionary with title and reference of all notebooks\n
# for request_reference=True\n
if request_reference:\n
if request_reference:\n
data_notebook_list = portal.portal_catalog(portal_type=\'Data Notebook\')\n
data_notebook_list = portal.portal_catalog(portal_type=\'Data Notebook\')\n
notebook_detail_list = [{\'reference\': obj.getReference(), \'title\': obj.getTitle()} for obj in data_notebook_list]\n
notebook_detail_list = [{\'reference\': obj.getReference(), \'title\': obj.getTitle()} for obj in data_notebook_list]\n
...
@@ -79,15 +93,16 @@ if not reference:\n
...
@@ -79,15 +93,16 @@ if not reference:\n
message = "Please set or use reference for the notebook you want to use"\n
message = "Please set or use reference for the notebook you want to use"\n
return message\n
return message\n
\n
\n
# Take python_expression as \'\' for empty code from jupyter frontend\n
if not python_expression:\n
if not python_expression:\n
python_expression = \'\'\n
python_expression = \'\'\n
\n
\n
data_notebook_list = portal.portal_catalog(portal_type=\'Data Notebook\',\n
# Get Data Notebook with the specific reference\n
data_notebook = portal.portal_catalog.getResultValue(portal_type=\'Data Notebook\',\n
reference=reference)\n
reference=reference)\n
\n
\n
if data_notebook_list:\n
# Create new Data Notebook if reference doesn\'t match with any from existing ones\n
data_notebook = data_notebook_list[0]\n
if not data_notebook:\n
else:\n
notebook_module = portal.getDefaultModule(portal_type=\'Data Notebook\')\n
notebook_module = portal.getDefaultModule(portal_type=\'Data Notebook\')\n
data_notebook = notebook_module.DataNotebookModule_addDataNotebook(\n
data_notebook = notebook_module.DataNotebookModule_addDataNotebook(\n
title=title,\n
title=title,\n
...
@@ -95,21 +110,26 @@ else:\n
...
@@ -95,21 +110,26 @@ else:\n
batch_mode=True\n
batch_mode=True\n
)\n
)\n
\n
\n
# Add new Data Notebook Message to the Data Notebook\n
data_notebook_message = data_notebook.DataNotebook_addDataNotebookMessage(\n
data_notebook_message = data_notebook.DataNotebook_addDataNotebookMessage(\n
notebook_code=python_expression,\n
notebook_code=python_expression,\n
batch_mode=True\n
batch_mode=True\n
)\n
)\n
\n
\n
#
Getting
active_process associated with data_notebook object\n
#
Get
active_process associated with data_notebook object\n
process_id = data_notebook.getProcess()\n
process_id = data_notebook.getProcess()\n
active_process = portal.portal_activities[process_id]\n
active_process = portal.portal_activities[process_id]\n
# Add a result object to Active Process object\n
result_list = active_process.getResultList()\n
result_list = active_process.getResultList()\n
\n
\n
# Get local variables saves in Active Result, local varibales are saved as\n
# persistent mapping object\n
old_local_variable_dict = result_list[0].summary\n
old_local_variable_dict = result_list[0].summary\n
if not old_local_variable_dict:\n
if not old_local_variable_dict:\n
old_local_variable_dict = context.Base_addPersistentMapping()\n
old_local_variable_dict = context.Base_addPersistentMapping()\n
\n
\n
# pass all to code runner\n
# Pass all to code Base_runJupyter external function which would execute the code\n
# and returns a dict of result\n
final_result = context.Base_runJupyter(python_expression, old_local_variable_dict)\n
final_result = context.Base_runJupyter(python_expression, old_local_variable_dict)\n
code_result = final_result[\'result_string\']\n
code_result = final_result[\'result_string\']\n
new_local_variable_dict = final_result[\'local_variable_dict\']\n
new_local_variable_dict = final_result[\'local_variable_dict\']\n
...
@@ -118,6 +138,8 @@ evalue = final_result[\'evalue\']\n
...
@@ -118,6 +138,8 @@ evalue = final_result[\'evalue\']\n
traceback = final_result[\'traceback\']\n
traceback = final_result[\'traceback\']\n
status = final_result[\'status\']\n
status = final_result[\'status\']\n
\n
\n
# Call to function to update persistent mapping object with new local variables\n
# and save the variables in the Active Result pertaining to the current Data Notebook\n
new_dict = context.Base_updatePersistentMapping(new_local_variable_dict)\n
new_dict = context.Base_updatePersistentMapping(new_local_variable_dict)\n
result_list[0].edit(summary=new_dict)\n
result_list[0].edit(summary=new_dict)\n
\n
\n
...
@@ -129,6 +151,7 @@ result = {\n
...
@@ -129,6 +151,7 @@ result = {\n
u\'status\': status\n
u\'status\': status\n
}\n
}\n
\n
\n
# Catch exception while seriaizing the result to be passed to jupyter frontend\n
try:\n
try:\n
serialized_result = json.dumps(result)\n
serialized_result = json.dumps(result)\n
data_notebook_message.edit(notebook_code_result=code_result)\n
data_notebook_message.edit(notebook_code_result=code_result)\n
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment