##// END OF EJS Templates
proper '.py' and '.ipynb' download files
Zachary Sailer -
Show More
@@ -69,16 +69,21 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)
75 self.set_header('Last-Modified', last_mod)
74 76
77 if download == 'True':
75 78 if format == u'json':
76 79 self.set_header('Content-Type', 'application/json')
77 80 self.set_header('Content-Disposition','attachment; filename="%s.ipynb"' % name)
81 self.finish(representation)
78 82 elif format == u'py':
79 83 self.set_header('Content-Type', 'application/x-python')
80 84 self.set_header('Content-Disposition','attachment; filename="%s.py"' % name)
81 #self.set_header('Last-Modified', last_mod)
85 self.finish(representation)
86 else:
82 87 self.finish(jsonapi.dumps(model))
83 88
84 89 @web.authenticated
@@ -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