Show More
@@ -21,6 +21,7 b' import io' | |||||
21 | import os |
|
21 | import os | |
22 | import glob |
|
22 | import glob | |
23 | import shutil |
|
23 | import shutil | |
|
24 | import ast | |||
24 |
|
25 | |||
25 | from unicodedata import normalize |
|
26 | from unicodedata import normalize | |
26 |
|
27 | |||
@@ -74,7 +75,6 b' class FileNotebookManager(NotebookManager):' | |||||
74 |
|
75 | |||
75 | filename_ext = Unicode(u'.ipynb') |
|
76 | filename_ext = Unicode(u'.ipynb') | |
76 |
|
77 | |||
77 | rev_mapping = Dict() |
|
|||
78 |
|
78 | |||
79 | def get_notebook_names(self, path): |
|
79 | def get_notebook_names(self, path): | |
80 | """List all notebook names in the notebook dir.""" |
|
80 | """List all notebook names in the notebook dir.""" | |
@@ -87,13 +87,29 b' class FileNotebookManager(NotebookManager):' | |||||
87 |
|
87 | |||
88 | def list_notebooks(self, path): |
|
88 | def list_notebooks(self, path): | |
89 | """List all notebooks in the notebook dir.""" |
|
89 | """List all notebooks in the notebook dir.""" | |
90 | names = self.get_notebook_names(path) |
|
90 | notebook_names = self.get_notebook_names(path) | |
|
91 | notebook_mapping = [] | |||
|
92 | for name in notebook_names: | |||
|
93 | model = self.notebook_model(name, path) | |||
|
94 | notebook_mapping.append(model) | |||
|
95 | return notebook_mapping | |||
91 |
|
96 | |||
92 | data = [] |
|
97 | def change_notebook(self, data, notebook_name, notebook_path=None): | |
93 | for name in names: |
|
98 | """Changes notebook""" | |
94 | data.append(name) |
|
99 | full_path = self.get_path(notebook_name, notebook_path) | |
95 | #data = sorted(data, key=lambda item: item['name']) |
|
100 | changes = data.keys() | |
96 |
r |
|
101 | for change in changes: | |
|
102 | if change == "notebook_name": | |||
|
103 | os.rename(notebook_name, data['notebook_name']) | |||
|
104 | notebook_name = data['notebook_name'] | |||
|
105 | if change == "notebook_path": | |||
|
106 | new_path = self.get_path(data['notebook_name'], data['notebook_path']) | |||
|
107 | stutil.move(old_path, new_path) | |||
|
108 | notebook_path = data['notebook_path'] | |||
|
109 | if change == "content": | |||
|
110 | self.save_notebook(data, notebook_name, notebook_path) | |||
|
111 | model = self.notebook_model(notebook_name, notebook_path) | |||
|
112 | return model | |||
97 |
|
113 | |||
98 | def notebook_exists(self, notebook_name): |
|
114 | def notebook_exists(self, notebook_name): | |
99 | """Does a notebook exist?""" |
|
115 | """Does a notebook exist?""" | |
@@ -103,7 +119,6 b' class FileNotebookManager(NotebookManager):' | |||||
103 | path = self.get_path_by_name(self.mapping[notebook_name]) |
|
119 | path = self.get_path_by_name(self.mapping[notebook_name]) | |
104 | return os.path.isfile(path) |
|
120 | return os.path.isfile(path) | |
105 |
|
121 | |||
106 |
|
||||
107 | def get_path(self, notebook_name, notebook_path=None): |
|
122 | def get_path(self, notebook_name, notebook_path=None): | |
108 | """Return a full path to a notebook given its notebook_name.""" |
|
123 | """Return a full path to a notebook given its notebook_name.""" | |
109 | return self.get_path_by_name(notebook_name, notebook_path) |
|
124 | return self.get_path_by_name(notebook_name, notebook_path) | |
@@ -145,16 +160,16 b' class FileNotebookManager(NotebookManager):' | |||||
145 | nb.metadata.name = os.path.splitext(os.path.basename(path))[0] |
|
160 | nb.metadata.name = os.path.splitext(os.path.basename(path))[0] | |
146 | return last_modified, nb |
|
161 | return last_modified, nb | |
147 |
|
162 | |||
148 | def write_notebook_object(self, nb, notebook_name=None, notebook_path=None): |
|
163 | def write_notebook_object(self, nb, notebook_name=None, notebook_path=None, new_name= None): | |
149 | """Save an existing notebook object by notebook_name.""" |
|
164 | """Save an existing notebook object by notebook_name.""" | |
150 | try: |
|
165 | if new_name == None: | |
151 | new_name = normalize('NFC', nb.metadata.name) |
|
166 | try: | |
152 | except AttributeError: |
|
167 | new_name = normalize('NFC', nb.metadata.name) | |
153 | raise web.HTTPError(400, u'Missing notebook name') |
|
168 | except AttributeError: | |
154 |
|
169 | raise web.HTTPError(400, u'Missing notebook name') | ||
|
170 | ||||
155 | new_path = notebook_path |
|
171 | new_path = notebook_path | |
156 | old_name = notebook_name |
|
172 | old_name = notebook_name | |
157 | # old_name = self.mapping[notebook_name] |
|
|||
158 | old_checkpoints = self.list_checkpoints(old_name) |
|
173 | old_checkpoints = self.list_checkpoints(old_name) | |
159 |
|
174 | |||
160 | path = self.get_path_by_name(new_name, new_path) |
|
175 | path = self.get_path_by_name(new_name, new_path) |
@@ -17,6 +17,7 b' Authors:' | |||||
17 | #----------------------------------------------------------------------------- |
|
17 | #----------------------------------------------------------------------------- | |
18 |
|
18 | |||
19 | from tornado import web |
|
19 | from tornado import web | |
|
20 | import ast | |||
20 |
|
21 | |||
21 | from zmq.utils import jsonapi |
|
22 | from zmq.utils import jsonapi | |
22 |
|
23 | |||
@@ -35,11 +36,7 b' class NotebookRootHandler(IPythonHandler):' | |||||
35 | def get(self): |
|
36 | def get(self): | |
36 | nbm = self.notebook_manager |
|
37 | nbm = self.notebook_manager | |
37 | km = self.kernel_manager |
|
38 | km = self.kernel_manager | |
38 |
notebook |
|
39 | notebooks = nbm.list_notebooks("") | |
39 | notebooks = [] |
|
|||
40 | for name in notebook_names: |
|
|||
41 | model = nbm.notebook_model(name) |
|
|||
42 | notebooks.append(model) |
|
|||
43 | self.finish(jsonapi.dumps(notebooks)) |
|
40 | self.finish(jsonapi.dumps(notebooks)) | |
44 |
|
41 | |||
45 | @web.authenticated |
|
42 | @web.authenticated | |
@@ -60,7 +57,7 b' class NotebookRootRedirect(IPythonHandler):' | |||||
60 |
|
57 | |||
61 | class NotebookHandler(IPythonHandler): |
|
58 | class NotebookHandler(IPythonHandler): | |
62 |
|
59 | |||
63 | SUPPORTED_METHODS = ('GET', 'PUT', 'DELETE') |
|
60 | SUPPORTED_METHODS = ('GET', 'PUT', 'PATCH', 'DELETE') | |
64 |
|
61 | |||
65 | @web.authenticated |
|
62 | @web.authenticated | |
66 | def get(self, notebook_path): |
|
63 | def get(self, notebook_path): | |
@@ -68,11 +65,7 b' class NotebookHandler(IPythonHandler):' | |||||
68 | name, path = nbm.named_notebook_path(notebook_path) |
|
65 | name, path = nbm.named_notebook_path(notebook_path) | |
69 |
|
66 | |||
70 | if name == None: |
|
67 | if name == None: | |
71 |
notebook |
|
68 | notebooks = nbm.list_notebooks(path) | |
72 | notebooks = [] |
|
|||
73 | for name in notebook_names: |
|
|||
74 | model = nbm.notebook_model(name,path) |
|
|||
75 | notebooks.append(model) |
|
|||
76 | self.finish(jsonapi.dumps(notebooks)) |
|
69 | self.finish(jsonapi.dumps(notebooks)) | |
77 | else: |
|
70 | else: | |
78 | format = self.get_argument('format', default='json') |
|
71 | format = self.get_argument('format', default='json') | |
@@ -89,6 +82,15 b' class NotebookHandler(IPythonHandler):' | |||||
89 | self.finish(jsonapi.dumps(model)) |
|
82 | self.finish(jsonapi.dumps(model)) | |
90 |
|
83 | |||
91 | @web.authenticated |
|
84 | @web.authenticated | |
|
85 | def patch(self, notebook_path): | |||
|
86 | nbm = self.notebook_manager | |||
|
87 | notebook_name, notebook_path = nbm.named_notebook_path(notebook_path) | |||
|
88 | data = jsonapi.loads(self.request.body) | |||
|
89 | model = nbm.change_notebook(data, notebook_name, notebook_path) | |||
|
90 | self.log.info(model) | |||
|
91 | self.finish(jsonapi.dumps(model)) | |||
|
92 | ||||
|
93 | @web.authenticated | |||
92 | def put(self, notebook_path): |
|
94 | def put(self, notebook_path): | |
93 | nbm = self.notebook_manager |
|
95 | nbm = self.notebook_manager | |
94 | notebook_name, notebook_path = nbm.named_notebook_path(notebook_path) |
|
96 | notebook_name, notebook_path = nbm.named_notebook_path(notebook_path) |
@@ -150,17 +150,17 b' class NotebookManager(LoggingConfigurable):' | |||||
150 | raise web.HTTPError(400, u'Invalid JSON data') |
|
150 | raise web.HTTPError(400, u'Invalid JSON data') | |
151 |
|
151 | |||
152 | if name is None: |
|
152 | if name is None: | |
153 |
|
|
153 | try: | |
154 |
|
|
154 | name = nb.metadata.name | |
155 |
|
|
155 | except AttributeError: | |
156 |
|
|
156 | raise web.HTTPError(400, u'Missing notebook name') | |
157 | nb.metadata.name = name |
|
157 | nb.metadata.name = name | |
158 |
|
158 | |||
159 | notebook_name = self.write_notebook_object(nb, notebook_path=notebook_path) |
|
159 | notebook_name = self.write_notebook_object(nb, notebook_path=notebook_path) | |
160 | return notebook_name |
|
160 | return notebook_name | |
161 |
|
161 | |||
162 | def save_notebook(self, data, notebook_path=None, name=None, format=u'json'): |
|
162 | def save_notebook(self, data, notebook_path=None, name=None, new_name=None, format=u'json'): | |
163 |
"""Save an existing notebook by notebook_ |
|
163 | """Save an existing notebook by notebook_name.""" | |
164 | if format not in self.allowed_formats: |
|
164 | if format not in self.allowed_formats: | |
165 | raise web.HTTPError(415, u'Invalid notebook format: %s' % format) |
|
165 | raise web.HTTPError(415, u'Invalid notebook format: %s' % format) | |
166 |
|
166 | |||
@@ -171,9 +171,9 b' class NotebookManager(LoggingConfigurable):' | |||||
171 |
|
171 | |||
172 | if name is not None: |
|
172 | if name is not None: | |
173 | nb.metadata.name = name |
|
173 | nb.metadata.name = name | |
174 | self.write_notebook_object(nb, name, notebook_path) |
|
174 | self.write_notebook_object(nb, name, notebook_path, new_name) | |
175 |
|
175 | |||
176 | def write_notebook_object(self, nb, notebook_name=None, notebook_path=None): |
|
176 | def write_notebook_object(self, nb, notebook_name=None, notebook_path=None, new_name=None): | |
177 | """Write a notebook object and return its notebook_name. |
|
177 | """Write a notebook object and return its notebook_name. | |
178 |
|
178 | |||
179 | If notebook_name is None, this method should create a new notebook_name. |
|
179 | If notebook_name is None, this method should create a new notebook_name. |
@@ -59,26 +59,27 b' class SessionRootHandler(IPythonHandler):' | |||||
59 |
|
59 | |||
60 | class SessionHandler(IPythonHandler): |
|
60 | class SessionHandler(IPythonHandler): | |
61 |
|
61 | |||
62 | @web.authenticated |
|
62 | SUPPORTED_METHODS = ('GET', 'PATCH', 'DELETE') | |
|
63 | ||||
|
64 | @authenticate_unless_readonly | |||
63 | def get(self, session_id): |
|
65 | def get(self, session_id): | |
64 | sm = self.session_manager |
|
66 | sm = self.session_manager | |
65 | model = sm.get_session_from_id(session_id) |
|
67 | model = sm.get_session_from_id(session_id) | |
66 | self.finish(jsonapi.dumps(model)) |
|
68 | self.finish(jsonapi.dumps(model)) | |
67 |
|
69 | |||
68 |
|
70 | @web.authenticated | ||
69 | @authenticate_unless_readonly |
|
71 | def patch(self, session_id): | |
70 | def put(self, session_id): |
|
|||
71 | sm = self.session_manager |
|
72 | sm = self.session_manager | |
72 | nbm = self.notebook_manager |
|
73 | nbm = self.notebook_manager | |
73 | km = self.kernel_manager |
|
74 | km = self.kernel_manager | |
74 |
notebook_path = self. |
|
75 | notebook_path = self.request.body | |
75 | notebook_name, path = nbm.named_notebook_path(notebook_path) |
|
76 | notebook_name, path = nbm.named_notebook_path(notebook_path) | |
76 | kernel_id = sm.get_kernel_from_session(session_id) |
|
77 | kernel_id = sm.get_kernel_from_session(session_id) | |
77 | kernel = km.kernel_model(kernel_id, self.ws_url) |
|
78 | kernel = km.kernel_model(kernel_id, self.ws_url) | |
78 | sm.delete_mapping_for_session(session_id) |
|
79 | sm.delete_mapping_for_session(session_id) | |
79 | model = sm.session_model(session_id, notebook_name, path, kernel) |
|
80 | model = sm.session_model(session_id, notebook_name, path, kernel) | |
80 | self.finish(jsonapi.dumps(model)) |
|
81 | self.finish(jsonapi.dumps(model)) | |
81 |
|
82 | |||
82 | @web.authenticated |
|
83 | @web.authenticated | |
83 | def delete(self, session_id): |
|
84 | def delete(self, session_id): | |
84 | sm = self.session_manager |
|
85 | sm = self.session_manager |
@@ -1664,7 +1664,7 b' var IPython = (function (IPython) {' | |||||
1664 |
|
1664 | |||
1665 | // time the ajax call for autosave tuning purposes. |
|
1665 | // time the ajax call for autosave tuning purposes. | |
1666 | var start = new Date().getTime(); |
|
1666 | var start = new Date().getTime(); | |
1667 |
|
1667 | console.log(JSON.stringify(data)) | ||
1668 | // We do the call with settings so we can set cache to false. |
|
1668 | // We do the call with settings so we can set cache to false. | |
1669 | var settings = { |
|
1669 | var settings = { | |
1670 | processData : false, |
|
1670 | processData : false, | |
@@ -1730,6 +1730,32 b' var IPython = (function (IPython) {' | |||||
1730 | Notebook.prototype.save_notebook_error = function (xhr, status, error_msg) { |
|
1730 | Notebook.prototype.save_notebook_error = function (xhr, status, error_msg) { | |
1731 | $([IPython.events]).trigger('notebook_save_failed.Notebook'); |
|
1731 | $([IPython.events]).trigger('notebook_save_failed.Notebook'); | |
1732 | }; |
|
1732 | }; | |
|
1733 | ||||
|
1734 | ||||
|
1735 | Notebook.prototype.notebook_rename = function (new_name) { | |||
|
1736 | var that = this; | |||
|
1737 | var name = {'notebook_name': new_name}; | |||
|
1738 | var settings = { | |||
|
1739 | processData : false, | |||
|
1740 | cache : false, | |||
|
1741 | type : "PATCH", | |||
|
1742 | data : JSON.stringify(name), | |||
|
1743 | dataType: "json", | |||
|
1744 | headers : {'Content-Type': 'application/json'}, | |||
|
1745 | success : $.proxy(that.rename_success, this) | |||
|
1746 | }; | |||
|
1747 | $([IPython.events]).trigger('notebook_rename.Notebook'); | |||
|
1748 | var url = this.baseProjectUrl() + 'api/notebooks/' + this.notebookPath()+ this.notebook_name; | |||
|
1749 | $.ajax(url, settings); | |||
|
1750 | }; | |||
|
1751 | ||||
|
1752 | ||||
|
1753 | Notebook.prototype.rename_success = function (json, status, xhr) { | |||
|
1754 | this.notebook_name = json.notebook_name | |||
|
1755 | var notebook_path = this.notebookPath() + this.notebook_name; | |||
|
1756 | this.session.notebook_rename(notebook_path); | |||
|
1757 | $([IPython.events]).trigger('notebook_renamed.Notebook'); | |||
|
1758 | } | |||
1733 |
|
1759 | |||
1734 | /** |
|
1760 | /** | |
1735 | * Request a notebook's data from the server. |
|
1761 | * Request a notebook's data from the server. |
@@ -46,6 +46,10 b' var IPython = (function (IPython) {' | |||||
46 | that.update_notebook_name(); |
|
46 | that.update_notebook_name(); | |
47 | that.update_document_title(); |
|
47 | that.update_document_title(); | |
48 | }); |
|
48 | }); | |
|
49 | $([IPython.events]).on('notebook_renamed.Notebook', function () { | |||
|
50 | that.update_notebook_name(); | |||
|
51 | that.update_document_title(); | |||
|
52 | }); | |||
49 | $([IPython.events]).on('notebook_save_failed.Notebook', function () { |
|
53 | $([IPython.events]).on('notebook_save_failed.Notebook', function () { | |
50 | that.set_save_status('Autosave Failed!'); |
|
54 | that.set_save_status('Autosave Failed!'); | |
51 | }); |
|
55 | }); | |
@@ -90,8 +94,7 b' var IPython = (function (IPython) {' | |||||
90 | ); |
|
94 | ); | |
91 | return false; |
|
95 | return false; | |
92 | } else { |
|
96 | } else { | |
93 |
IPython.notebook. |
|
97 | IPython.notebook.notebook_rename(new_name); | |
94 | IPython.notebook.save_notebook(); |
|
|||
95 | } |
|
98 | } | |
96 | }} |
|
99 | }} | |
97 | }, |
|
100 | }, | |
@@ -112,6 +115,7 b' var IPython = (function (IPython) {' | |||||
112 |
|
115 | |||
113 | SaveWidget.prototype.update_notebook_name = function () { |
|
116 | SaveWidget.prototype.update_notebook_name = function () { | |
114 | var nbname = IPython.notebook.get_notebook_name(); |
|
117 | var nbname = IPython.notebook.get_notebook_name(); | |
|
118 | console.log("UPDATED") | |||
115 | this.element.find('span#notebook_name').html(nbname); |
|
119 | this.element.find('span#notebook_name').html(nbname); | |
116 | }; |
|
120 | }; | |
117 |
|
121 |
@@ -30,8 +30,33 b' var IPython = (function (IPython) {' | |||||
30 | ); |
|
30 | ); | |
31 | }; |
|
31 | }; | |
32 |
|
32 | |||
|
33 | Session.prototype.notebook_rename = function (notebook_path) { | |||
|
34 | this.notebook_path = notebook_path; | |||
|
35 | console.log("TEST"); | |||
|
36 | var settings = { | |||
|
37 | processData : false, | |||
|
38 | cache : false, | |||
|
39 | type : "PATCH", | |||
|
40 | data: notebook_path, | |||
|
41 | dataType : "json", | |||
|
42 | }; | |||
|
43 | var url = this._baseProjectUrl + 'api/sessions/' + this.session_id; | |||
|
44 | $.ajax(url, settings); | |||
|
45 | } | |||
|
46 | ||||
|
47 | ||||
|
48 | Session.prototype.delete_session = function() { | |||
|
49 | var settings = { | |||
|
50 | processData : false, | |||
|
51 | cache : false, | |||
|
52 | type : "DELETE", | |||
|
53 | dataType : "json", | |||
|
54 | }; | |||
|
55 | var url = this._baseProjectUrl + 'api/sessions/' + this.session_id; | |||
|
56 | $.ajax(url, settings); | |||
|
57 | }; | |||
|
58 | ||||
33 | // Kernel related things |
|
59 | // Kernel related things | |
34 |
|
||||
35 | /** |
|
60 | /** | |
36 | * Start a new kernel and set it on each code cell. |
|
61 | * Start a new kernel and set it on each code cell. | |
37 | * |
|
62 | * | |
@@ -67,16 +92,6 b' var IPython = (function (IPython) {' | |||||
67 | this.kernel.interrupt(); |
|
92 | this.kernel.interrupt(); | |
68 | }; |
|
93 | }; | |
69 |
|
94 | |||
70 | Session.prototype.delete_session = function() { |
|
|||
71 | var settings = { |
|
|||
72 | processData : false, |
|
|||
73 | cache : false, |
|
|||
74 | type : "DELETE", |
|
|||
75 | dataType : "json", |
|
|||
76 | }; |
|
|||
77 | var url = this._baseProjectUrl + 'api/sessions/' + this.session_id; |
|
|||
78 | $.ajax(url, settings); |
|
|||
79 | }; |
|
|||
80 |
|
95 | |||
81 | Session.prototype.kill_kernel = function() { |
|
96 | Session.prototype.kill_kernel = function() { | |
82 | this.kernel.kill(); |
|
97 | this.kernel.kill(); |
@@ -103,7 +103,6 b' var IPython = (function (IPython) {' | |||||
103 | }; |
|
103 | }; | |
104 |
|
104 | |||
105 | NotebookList.prototype.load_sessions = function(){ |
|
105 | NotebookList.prototype.load_sessions = function(){ | |
106 | console.log("DID IT MAKE IT?"); |
|
|||
107 | var that = this; |
|
106 | var that = this; | |
108 | var settings = { |
|
107 | var settings = { | |
109 | processData : false, |
|
108 | processData : false, |
General Comments 0
You need to be logged in to leave comments.
Login now