|
@@ -31,8 +31,11 @@ from desktop.lib.rest.http_client import RestException
|
|
|
class Notebook():
|
|
class Notebook():
|
|
|
|
|
|
|
|
def __init__(self, document=None):
|
|
def __init__(self, document=None):
|
|
|
|
|
+ self.document = None
|
|
|
|
|
+
|
|
|
if document is not None:
|
|
if document is not None:
|
|
|
self.data = document.data
|
|
self.data = document.data
|
|
|
|
|
+ self.document = document
|
|
|
else:
|
|
else:
|
|
|
self.data = json.dumps({
|
|
self.data = json.dumps({
|
|
|
'name': 'My Notebook',
|
|
'name': 'My Notebook',
|
|
@@ -47,12 +50,17 @@ class Notebook():
|
|
|
def get_data(self):
|
|
def get_data(self):
|
|
|
_data = json.loads(self.data)
|
|
_data = json.loads(self.data)
|
|
|
|
|
|
|
|
|
|
+ if self.document is not None:
|
|
|
|
|
+ _data['id'] = self.document.id
|
|
|
|
|
+
|
|
|
return _data
|
|
return _data
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_api(user, snippet):
|
|
def get_api(user, snippet):
|
|
|
if snippet['type'] == 'hive':
|
|
if snippet['type'] == 'hive':
|
|
|
return HS2Api(user)
|
|
return HS2Api(user)
|
|
|
|
|
+ if snippet['type'] == 'text':
|
|
|
|
|
+ return TextApi(user)
|
|
|
else:
|
|
else:
|
|
|
return SparkApi(user)
|
|
return SparkApi(user)
|
|
|
|
|
|
|
@@ -61,6 +69,17 @@ def _get_snippet_session(notebook, snippet):
|
|
|
return [session for session in notebook['sessions'] if session['type'] == snippet['type']][0]
|
|
return [session for session in notebook['sessions'] if session['type'] == snippet['type']][0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+class TextApi():
|
|
|
|
|
+
|
|
|
|
|
+ def __init__(self, user):
|
|
|
|
|
+ self.user = user
|
|
|
|
|
+
|
|
|
|
|
+ def create_session(self, lang):
|
|
|
|
|
+ return {
|
|
|
|
|
+ 'type': lang,
|
|
|
|
|
+ 'id': None
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
class HS2Api():
|
|
class HS2Api():
|
|
|
|
|
|