##// END OF EJS Templates
Change new/copy URLS to POST requests
Zachary Sailer -
Show More
@@ -35,7 +35,13 b' class NotebookHandler(IPythonHandler):'
35
35
36 @web.authenticated
36 @web.authenticated
37 def post(self):
37 def post(self):
38 notebook_name = self.notebook_manager.new_notebook()
38 nbm = self.notebook_manager
39 data=self.request.body
40 if data == "":
41 notebook_name = nbm.new_notebook()
42 else:
43 data = jsonapi.loads(data)
44 notebook_name = nbm.copy_notebook(data['name'])
39 self.finish(jsonapi.dumps({"name": notebook_name}))
45 self.finish(jsonapi.dumps({"name": notebook_name}))
40
46
41
47
@@ -65,7 +71,13 b' class NamedNotebookHandler(IPythonHandler):'
65
71
66 @web.authenticated
72 @web.authenticated
67 def post(self, notebook_path):
73 def post(self, notebook_path):
68 notebook_name = self.notebook_manager.new_notebook(notebook_path)
74 nbm = self.notebook_manager
75 data = self.request.body
76 if data == "":
77 notebook_name = nbm.new_notebook(notebook_path)
78 else:
79 data = jsonapi.loads(data)
80 notebook_name = nbm.copy_notebook(data['name'], notebook_path)
69 self.finish(jsonapi.dumps({"name": notebook_name}))
81 self.finish(jsonapi.dumps({"name": notebook_name}))
70
82
71
83
@@ -142,7 +142,7 b' class FileNotebookManager(NotebookManager):'
142 raise web.HTTPError(400, msg, reason=msg)
142 raise web.HTTPError(400, msg, reason=msg)
143 return last_modified, nb
143 return last_modified, nb
144
144
145 def read_notebook_object(self, notebook_name, notebook_path):
145 def read_notebook_object(self, notebook_name, notebook_path=None):
146 """Get the Notebook representation of a notebook by notebook_name."""
146 """Get the Notebook representation of a notebook by notebook_name."""
147 path = self.get_path(notebook_name, notebook_path)
147 path = self.get_path(notebook_name, notebook_path)
148 if not os.path.isfile(path):
148 if not os.path.isfile(path):
@@ -157,7 +157,7 b' class NotebookManager(LoggingConfigurable):'
157 name = nb.metadata.get('name', 'notebook')
157 name = nb.metadata.get('name', 'notebook')
158 return last_mod, representation, name
158 return last_mod, representation, name
159
159
160 def read_notebook_object(self, notebook_name, notebook_path):
160 def read_notebook_object(self, notebook_name, notebook_path=None):
161 """Get the object representation of a notebook by notebook_id."""
161 """Get the object representation of a notebook by notebook_id."""
162 raise NotImplementedError('must be implemented in a subclass')
162 raise NotImplementedError('must be implemented in a subclass')
163
163
@@ -229,7 +229,7 b' class NotebookManager(LoggingConfigurable):'
229 notebook_name = self.write_notebook_object(nb, notebook_path=notebook_path)
229 notebook_name = self.write_notebook_object(nb, notebook_path=notebook_path)
230 return notebook_name
230 return notebook_name
231
231
232 def copy_notebook(self, name, path):
232 def copy_notebook(self, name, path=None):
233 """Copy an existing notebook and return its notebook_id."""
233 """Copy an existing notebook and return its notebook_id."""
234 last_mod, nb = self.read_notebook_object(name, path)
234 last_mod, nb = self.read_notebook_object(name, path)
235 name = nb.metadata.name + '-Copy'
235 name = nb.metadata.name + '-Copy'
@@ -84,9 +84,7 b' var IPython = (function (IPython) {'
84 window.open(that.baseProjectUrl() + 'tree/' + that.notebookPath());
84 window.open(that.baseProjectUrl() + 'tree/' + that.notebookPath());
85 });
85 });
86 this.element.find('#copy_notebook').click(function () {
86 this.element.find('#copy_notebook').click(function () {
87 var notebook_name = IPython.notebook.get_notebook_name();
87 IPython.notebook.copy_notebook();
88 var url = that.baseProjectUrl() + 'notebooks/' + that.notebookPath() + notebook_name + '/copy';
89 window.open(url,'_blank');
90 return false;
88 return false;
91 });
89 });
92 this.element.find('#download_ipynb').click(function () {
90 this.element.find('#download_ipynb').click(function () {
@@ -80,6 +80,7 b' var IPython = (function (IPython) {'
80
80
81 Notebook.prototype.notebookName = function() {
81 Notebook.prototype.notebookName = function() {
82 var name = $('body').data('notebookName');
82 var name = $('body').data('notebookName');
83 name = decodeURIComponent(name);
83 return name;
84 return name;
84 };
85 };
85
86
@@ -1759,6 +1760,23 b' var IPython = (function (IPython) {'
1759 $.ajax(url,settings);
1760 $.ajax(url,settings);
1760 };
1761 };
1761
1762
1763 Notebook.prototype.copy_notebook = function(){
1764 var path = this.notebookPath();
1765 var name = {'name': this.notebook_name}
1766 var settings = {
1767 processData : false,
1768 cache : false,
1769 type : "POST",
1770 data: JSON.stringify(name),
1771 dataType : "json",
1772 success:$.proxy(function (data, status, xhr){
1773 notebook_name = data.name;
1774 window.open(this._baseProjectUrl +'notebooks/' + this.notebookPath()+ notebook_name);
1775 }, this)
1776 };
1777 var url = this._baseProjectUrl + 'notebooks/' + path;
1778 $.ajax(url,settings);
1779 };
1762
1780
1763 Notebook.prototype.notebook_rename = function (nbname) {
1781 Notebook.prototype.notebook_rename = function (nbname) {
1764 var that = this;
1782 var that = this;
@@ -338,7 +338,21 b' var IPython = (function (IPython) {'
338 };
338 };
339
339
340
340
341
341 NotebookList.prototype.new_notebook = function(){
342 var path = this.notebookPath();
343 var settings = {
344 processData : false,
345 cache : false,
346 type : "POST",
347 dataType : "json",
348 success:$.proxy(function (data, status, xhr){
349 notebook_name = data.name;
350 window.open(this.baseProjectUrl() +'notebooks/' + this.notebookPath()+ notebook_name);
351 }, this)
352 };
353 var url = this.baseProjectUrl() + 'notebooks/' + path;
354 $.ajax(url,settings);
355 };
342
356
343 IPython.NotebookList = NotebookList;
357 IPython.NotebookList = NotebookList;
344
358
General Comments 0
You need to be logged in to leave comments. Login now