Show More
@@ -150,15 +150,19 b' class NotebookHandler(IPythonHandler):' | |||||
150 | POST /api/notebooks/path?copy=OtherNotebook.ipynb : new copy of OtherNotebook in path |
|
150 | POST /api/notebooks/path?copy=OtherNotebook.ipynb : new copy of OtherNotebook in path | |
151 | """ |
|
151 | """ | |
152 |
|
152 | |||
153 | model = self.get_json_body() |
|
|||
154 | copy = self.get_argument("copy", default="") |
|
|||
155 | if name is not None: |
|
153 | if name is not None: | |
156 | raise web.HTTPError(400, "Only POST to directories. Use PUT for full names") |
|
154 | raise web.HTTPError(400, "Only POST to directories. Use PUT for full names.") | |
|
155 | ||||
|
156 | model = self.get_json_body() | |||
157 |
|
157 | |||
158 | if copy: |
|
158 | if model is not None: | |
159 | self._copy_notebook(copy, path) |
|
159 | copy_from = model.get('copy_from') | |
160 | elif model: |
|
160 | if copy_from: | |
161 | self._upload_notebook(model, path) |
|
161 | if model.get('content'): | |
|
162 | raise web.HTTPError(400, "Can't upload and copy at the same time.") | |||
|
163 | self._copy_notebook(copy_from, path) | |||
|
164 | else: | |||
|
165 | self._upload_notebook(model, path) | |||
162 | else: |
|
166 | else: | |
163 | self._create_empty_notebook(path) |
|
167 | self._create_empty_notebook(path) | |
164 |
|
168 | |||
@@ -178,14 +182,15 b' class NotebookHandler(IPythonHandler):' | |||||
178 | """ |
|
182 | """ | |
179 | if name is None: |
|
183 | if name is None: | |
180 | raise web.HTTPError(400, "Only PUT to full names. Use POST for directories.") |
|
184 | raise web.HTTPError(400, "Only PUT to full names. Use POST for directories.") | |
|
185 | ||||
181 | model = self.get_json_body() |
|
186 | model = self.get_json_body() | |
182 | copy = self.get_argument("copy", default="") |
|
187 | if model: | |
183 | if copy: |
|
188 | copy_from = model.get('copy_from') | |
184 | if model is not None: |
|
189 | if copy_from: | |
185 | raise web.HTTPError(400) |
|
190 | if model.get('content'): | |
186 | self._copy_notebook(copy, path, name) |
|
191 | raise web.HTTPError(400, "Can't upload and copy at the same time.") | |
187 | elif model: |
|
192 | self._copy_notebook(copy_from, path, name) | |
188 | if self.notebook_manager.notebook_exists(name, path): |
|
193 | elif self.notebook_manager.notebook_exists(name, path): | |
189 | self._save_notebook(model, path, name) |
|
194 | self._save_notebook(model, path, name) | |
190 | else: |
|
195 | else: | |
191 | self._upload_notebook(model, path, name) |
|
196 | self._upload_notebook(model, path, name) |
@@ -2,6 +2,7 b'' | |||||
2 | """Test the notebooks webservice API.""" |
|
2 | """Test the notebooks webservice API.""" | |
3 |
|
3 | |||
4 | import io |
|
4 | import io | |
|
5 | import json | |||
5 | import os |
|
6 | import os | |
6 | import shutil |
|
7 | import shutil | |
7 | from unicodedata import normalize |
|
8 | from unicodedata import normalize | |
@@ -25,11 +26,10 b' class NBAPI(object):' | |||||
25 | def __init__(self, base_url): |
|
26 | def __init__(self, base_url): | |
26 | self.base_url = base_url |
|
27 | self.base_url = base_url | |
27 |
|
28 | |||
28 |
def _req(self, verb, path, body=None |
|
29 | def _req(self, verb, path, body=None): | |
29 | response = requests.request(verb, |
|
30 | response = requests.request(verb, | |
30 | url_path_join(self.base_url, 'api/notebooks', path), |
|
31 | url_path_join(self.base_url, 'api/notebooks', path), | |
31 | data=body, |
|
32 | data=body, | |
32 | params=params, |
|
|||
33 | ) |
|
33 | ) | |
34 | response.raise_for_status() |
|
34 | response.raise_for_status() | |
35 | return response |
|
35 | return response | |
@@ -47,7 +47,8 b' class NBAPI(object):' | |||||
47 | return self._req('POST', path, body) |
|
47 | return self._req('POST', path, body) | |
48 |
|
48 | |||
49 | def copy_untitled(self, copy_from, path='/'): |
|
49 | def copy_untitled(self, copy_from, path='/'): | |
50 | return self._req('POST', path, params={'copy':copy_from}) |
|
50 | body = json.dumps({'copy_from':copy_from}) | |
|
51 | return self._req('POST', path, body) | |||
51 |
|
52 | |||
52 | def create(self, name, path='/'): |
|
53 | def create(self, name, path='/'): | |
53 | return self._req('PUT', url_path_join(path, name)) |
|
54 | return self._req('PUT', url_path_join(path, name)) | |
@@ -56,7 +57,8 b' class NBAPI(object):' | |||||
56 | return self._req('PUT', url_path_join(path, name), body) |
|
57 | return self._req('PUT', url_path_join(path, name), body) | |
57 |
|
58 | |||
58 | def copy(self, copy_from, copy_to, path='/'): |
|
59 | def copy(self, copy_from, copy_to, path='/'): | |
59 | return self._req('PUT', url_path_join(path, copy_to), params={'copy':copy_from}) |
|
60 | body = json.dumps({'copy_from':copy_from}) | |
|
61 | return self._req('PUT', url_path_join(path, copy_to), body) | |||
60 |
|
62 | |||
61 | def save(self, name, body, path='/'): |
|
63 | def save(self, name, body, path='/'): | |
62 | return self._req('PUT', url_path_join(path, name), body) |
|
64 | return self._req('PUT', url_path_join(path, name), body) |
General Comments 0
You need to be logged in to leave comments.
Login now