##// END OF EJS Templates
Handle notebook downloads through the /files URL.
Brian E. Granger -
Show More
@@ -268,6 +268,10 class AuthenticatedFileHandler(IPythonHandler, web.StaticFileHandler):
268
268
269 @web.authenticated
269 @web.authenticated
270 def get(self, path):
270 def get(self, path):
271 if os.path.splitext(path)[1] == '.ipynb':
272 name = os.path.basename(path)
273 self.set_header('Content-Type', 'application/json')
274 self.set_header('Content-Disposition','attachment; filename="%s"' % name)
271 return web.StaticFileHandler.get(self, path)
275 return web.StaticFileHandler.get(self, path)
272
276
273
277
@@ -399,11 +403,6 class FileFindHandler(web.StaticFileHandler):
399 self.set_status(304)
403 self.set_status(304)
400 return
404 return
401
405
402 if os.path.splitext(path)[1] == '.ipynb':
403 name = os.path.basename(path)
404 self.set_header('Content-Type', 'application/json')
405 self.set_header('Content-Disposition','attachment; filename="%s"' % name)
406
407 with open(abspath, "rb") as file:
406 with open(abspath, "rb") as file:
408 data = file.read()
407 data = file.read()
409 hasher = hashlib.sha1()
408 hasher = hashlib.sha1()
@@ -64,19 +64,7 class NotebookHandler(IPythonHandler):
64 # get and return notebook representation
64 # get and return notebook representation
65 model = nbm.get_notebook_model(name, path)
65 model = nbm.get_notebook_model(name, path)
66 self.set_header(u'Last-Modified', model[u'last_modified'])
66 self.set_header(u'Last-Modified', model[u'last_modified'])
67
67 self.finish(json.dumps(model, default=date_default))
68 if self.get_argument('download', default='False') == 'True':
69 format = self.get_argument('format', default='json')
70 if format != u'json':
71 self.set_header('Content-Type', 'application/json')
72 raise web.HTTPError(400, "Unrecognized format: %s" % format)
73
74 self.set_header('Content-Disposition',
75 'attachment; filename="%s"' % name
76 )
77 self.finish(json.dumps(model['content'], default=date_default))
78 else:
79 self.finish(json.dumps(model, default=date_default))
80
68
81 @web.authenticated
69 @web.authenticated
82 @json_errors
70 @json_errors
@@ -95,9 +95,9 var IPython = (function (IPython) {
95
95
96 var url = utils.url_path_join(
96 var url = utils.url_path_join(
97 that.baseProjectUrl(),
97 that.baseProjectUrl(),
98 'api/notebooks',
98 'files',
99 that.notebookPath(),
99 that.notebookPath(),
100 notebook_name + '.ipynb?format=json&download=True'
100 notebook_name + '.ipynb'
101 );
101 );
102 window.location.assign(url);
102 window.location.assign(url);
103 });
103 });
General Comments 0
You need to be logged in to leave comments. Login now