##// END OF EJS Templates
Merge pull request #6827 from minrk/not-attachment...
Thomas Kluyver -
r18558:41c88ae1 merge
parent child Browse files
Show More
@@ -24,7 +24,10 b' class FilesHandler(IPythonHandler):'
24
24
25 path, name = os.path.split(path)
25 path, name = os.path.split(path)
26 model = cm.get_model(name, path)
26 model = cm.get_model(name, path)
27
27
28 if self.get_argument("download", False):
29 self.set_header('Content-Disposition','attachment; filename="%s"' % name)
30
28 if model['type'] == 'notebook':
31 if model['type'] == 'notebook':
29 self.set_header('Content-Type', 'application/json')
32 self.set_header('Content-Type', 'application/json')
30 else:
33 else:
@@ -32,8 +35,6 b' class FilesHandler(IPythonHandler):'
32 if cur_mime is not None:
35 if cur_mime is not None:
33 self.set_header('Content-Type', cur_mime)
36 self.set_header('Content-Type', cur_mime)
34
37
35 self.set_header('Content-Disposition','attachment; filename="%s"' % name)
36
37 if model['format'] == 'base64':
38 if model['format'] == 'base64':
38 b64_bytes = model['content'].encode('ascii')
39 b64_bytes = model['content'].encode('ascii')
39 self.write(base64.decodestring(b64_bytes))
40 self.write(base64.decodestring(b64_bytes))
@@ -112,7 +112,7 b' define(['
112 notebook_path,
112 notebook_path,
113 notebook_name
113 notebook_name
114 );
114 );
115 window.open(url);
115 window.open(url + '?download=1');
116 });
116 });
117
117
118 this.element.find('#print_preview').click(function () {
118 this.element.find('#print_preview').click(function () {
@@ -98,7 +98,23 b' class FilesTest(NotebookTestBase):'
98 self.assertEqual(r.status_code, 200)
98 self.assertEqual(r.status_code, 200)
99 self.assertEqual(r.headers['content-type'], 'text/plain')
99 self.assertEqual(r.headers['content-type'], 'text/plain')
100 self.assertEqual(r.text, 'foobar')
100 self.assertEqual(r.text, 'foobar')
101
102 def test_download(self):
103 nbdir = self.notebook_dir.name
104 base = self.base_url()
105
106 text = 'hello'
107 with open(pjoin(nbdir, 'test.txt'), 'w') as f:
108 f.write(text)
109
110 r = requests.get(url_path_join(base, 'files', 'test.txt'))
111 disposition = r.headers.get('Content-Disposition', '')
112 self.assertNotIn('attachment', disposition)
101
113
114 r = requests.get(url_path_join(base, 'files', 'test.txt') + '?download=1')
115 disposition = r.headers.get('Content-Disposition', '')
116 self.assertIn('attachment', disposition)
117 self.assertIn('filename="test.txt"', disposition)
102
118
103 def test_old_files_redirect(self):
119 def test_old_files_redirect(self):
104 """pre-2.0 'files/' prefixed links are properly redirected"""
120 """pre-2.0 'files/' prefixed links are properly redirected"""
General Comments 0
You need to be logged in to leave comments. Login now