Commit c5fef63e authored by Yusei Tahara's avatar Yusei Tahara

Jupyter: Make the looks of ERP5 kernel more close to the normal python kernel's.

parent eb6f94c1
...@@ -43,7 +43,7 @@ md5sum = d7d4a7e19d55bf14007819258bf42100 ...@@ -43,7 +43,7 @@ md5sum = d7d4a7e19d55bf14007819258bf42100
[erp5-kernel] [erp5-kernel]
<= download-file-base <= download-file-base
filename = ERP5kernel.py.jinja filename = ERP5kernel.py.jinja
md5sum = 24308ca010532863dbcf501f011f9846 md5sum = cbd35bbe54b66e9b2f73487ecdbc6976
[kernel-json] [kernel-json]
<= download-file-base <= download-file-base
......
...@@ -215,6 +215,8 @@ class ERP5Kernel(Kernel): ...@@ -215,6 +215,8 @@ class ERP5Kernel(Kernel):
code = code.strip() code = code.strip()
extra_data_list = [] extra_data_list = []
print_result = {}
displayhook_result = {}
if code.startswith('%'): if code.startswith('%'):
# No need to try-catch here as its already been taken that the code # No need to try-catch here as its already been taken that the code
...@@ -270,12 +272,17 @@ class ERP5Kernel(Kernel): ...@@ -270,12 +272,17 @@ class ERP5Kernel(Kernel):
# "evalue": null, # "evalue": null,
# "traceback": null, # "traceback": null,
# "code_result": "", # "code_result": "",
# "mime_type": "text/plain" # "print_result": {},
# "displayhook_result": {},
# "mime_type": "text/plain",
# "extra_data_list": []
# } # }
# So, we can easily use any of the key to update values as such. # So, we can easily use any of the key to update values as such.
# Getting code_result for succesfull execution of code # Getting code_result for succesfull execution of code
code_result = content['code_result'] code_result = content['code_result']
print_result = content['print_result']
displayhook_result = content['displayhook_result']
# Update mime_type with the mime_type from the http response result # Update mime_type with the mime_type from the http response result
# Required in case the mime_type is anything other than 'text/plain' # Required in case the mime_type is anything other than 'text/plain'
...@@ -297,21 +304,26 @@ class ERP5Kernel(Kernel): ...@@ -297,21 +304,26 @@ class ERP5Kernel(Kernel):
except ValueError: except ValueError:
content = self.response content = self.response
code_result = content code_result = content
print_result = {'data':{'text/plain':content}, 'metadata':{}}
# Display basic error message to frontend in case of error on server side # Display basic error message to frontend in case of error on server side
else: else:
self.make_erp5_request(code=code) self.make_erp5_request(code=code)
code_result = "Error at Server Side" code_result = "Error at Server Side"
print_result = {'data':{'text/plain':'Error at Server Side'}, 'metadata':{}}
mime_type = 'text/plain' mime_type = 'text/plain'
# For all status_code except allowed_HTTP_response_code_list show unauthorized message # For all status_code except allowed_HTTP_response_code_list show unauthorized message
else: else:
code_result = 'Unauthorized access' code_result = 'Unauthorized access'
print_result = {'data':{'text/plain':'Unauthorized access'}, 'metadata':{}}
mime_type = 'text/plain' mime_type = 'text/plain'
data = { if print_result.get('data'):
'data': {mime_type: code_result}, self.send_response(self.iopub_socket, 'display_data', print_result)
'metadata': {}}
self.send_response(self.iopub_socket, 'display_data', data) if displayhook_result.get('data'):
displayhook_result['execution_count'] = self.execution_count
self.send_response(self.iopub_socket, 'execute_result', displayhook_result)
for extra_data in extra_data_list: for extra_data in extra_data_list:
self.send_response(self.iopub_socket, 'display_data', extra_data) self.send_response(self.iopub_socket, 'display_data', extra_data)
......
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