##// END OF EJS Templates
proper '.py' and '.ipynb' download files
Zachary Sailer -
Show More
@@ -69,17 +69,22 b' class NotebookHandler(IPythonHandler):'
69 69 self.finish(jsonapi.dumps(notebooks))
70 70 else:
71 71 format = self.get_argument('format', default='json')
72 download = self.get_argument('download', default='False')
72 73 model = nbm.notebook_model(name,path)
73 74 last_mod, representation, name = nbm.get_notebook(name, path, format)
74
75 if format == u'json':
76 self.set_header('Content-Type', 'application/json')
77 self.set_header('Content-Disposition','attachment; filename="%s.ipynb"' % name)
78 elif format == u'py':
79 self.set_header('Content-Type', 'application/x-python')
80 self.set_header('Content-Disposition','attachment; filename="%s.py"' % name)
81 #self.set_header('Last-Modified', last_mod)
82 self.finish(jsonapi.dumps(model))
75 self.set_header('Last-Modified', last_mod)
76
77 if download == 'True':
78 if format == u'json':
79 self.set_header('Content-Type', 'application/json')
80 self.set_header('Content-Disposition','attachment; filename="%s.ipynb"' % name)
81 self.finish(representation)
82 elif format == u'py':
83 self.set_header('Content-Type', 'application/x-python')
84 self.set_header('Content-Disposition','attachment; filename="%s.py"' % name)
85 self.finish(representation)
86 else:
87 self.finish(jsonapi.dumps(model))
83 88
84 89 @web.authenticated
85 90 def patch(self, notebook_path):
@@ -91,14 +91,14 b' var IPython = (function (IPython) {'
91 91 });
92 92 this.element.find('#download_ipynb').click(function () {
93 93 var notebook_name = IPython.notebook.get_notebook_name();
94 var url = that.baseProjectUrl() + 'api/notebooks/' +
95 notebook_name + '?format=json';
94 var url = that.baseProjectUrl() + 'api/notebooks/' + that.notebookPath() +
95 notebook_name + '?format=json'+ '&download=True';
96 96 window.location.assign(url);
97 97 });
98 98 this.element.find('#download_py').click(function () {
99 99 var notebook_name = IPython.notebook.get_notebook_name();
100 var url = that.baseProjectUrl() + 'api/notebooks/' +
101 notebook_name + '?format=py';
100 var url = that.baseProjectUrl() + 'api/notebooks/' + that.notebookPath() +
101 notebook_name + '?format=py' + '&download=True';
102 102 window.location.assign(url);
103 103 });
104 104 this.element.find('#rename_notebook').click(function () {
General Comments 0
You need to be logged in to leave comments. Login now