Show More
@@ -117,13 +117,19 b' class ContentsHandler(IPythonHandler):' | |||
|
117 | 117 | format = self.get_query_argument('format', default=None) |
|
118 | 118 | if format not in {None, 'text', 'base64'}: |
|
119 | 119 | raise web.HTTPError(400, u'Format %r is invalid' % format) |
|
120 | ||
|
121 | model = yield gen.maybe_future(self.contents_manager.get(path=path, type=type, format=format)) | |
|
122 | if model['type'] == 'directory': | |
|
120 | content = self.get_query_argument('content', default='1') | |
|
121 | if content not in {'0', '1'}: | |
|
122 | raise web.HTTPError(400, u'Content %r is invalid' % content) | |
|
123 | content = int(content) | |
|
124 | ||
|
125 | model = yield gen.maybe_future(self.contents_manager.get( | |
|
126 | path=path, type=type, format=format, content=content, | |
|
127 | )) | |
|
128 | if model['type'] == 'directory' and content: | |
|
123 | 129 | # group listing by type, then by name (case-insensitive) |
|
124 | 130 | # FIXME: sorting should be done in the frontends |
|
125 | 131 | model['content'].sort(key=sort_key) |
|
126 |
validate_model(model, expect_content= |
|
|
132 | validate_model(model, expect_content=content) | |
|
127 | 133 | self._finish_model(model, location=False) |
|
128 | 134 | |
|
129 | 135 | @web.authenticated |
@@ -51,12 +51,14 b' class API(object):' | |||
|
51 | 51 | def list(self, path='/'): |
|
52 | 52 | return self._req('GET', path) |
|
53 | 53 | |
|
54 | def read(self, path, type=None, format=None): | |
|
54 | def read(self, path, type=None, format=None, content=None): | |
|
55 | 55 | params = {} |
|
56 | 56 | if type is not None: |
|
57 | 57 | params['type'] = type |
|
58 | 58 | if format is not None: |
|
59 | 59 | params['format'] = format |
|
60 | if content == False: | |
|
61 | params['content'] = '0' | |
|
60 | 62 | return self._req('GET', path, params=params) |
|
61 | 63 | |
|
62 | 64 | def create_untitled(self, path='/', ext='.ipynb'): |
@@ -243,6 +245,14 b' class APITest(NotebookTestBase):' | |||
|
243 | 245 | dir_names = {normalize('NFC', d['name']) for d in dirs} |
|
244 | 246 | self.assertEqual(dir_names, self.top_level_dirs) # Excluding hidden dirs |
|
245 | 247 | |
|
248 | def test_get_dir_no_content(self): | |
|
249 | for d in self.dirs: | |
|
250 | model = self.api.read(d, content=False).json() | |
|
251 | self.assertEqual(model['path'], d) | |
|
252 | self.assertEqual(model['type'], 'directory') | |
|
253 | self.assertIn('content', model) | |
|
254 | self.assertEqual(model['content'], None) | |
|
255 | ||
|
246 | 256 | def test_list_nonexistant_dir(self): |
|
247 | 257 | with assert_http_error(404): |
|
248 | 258 | self.api.list('nonexistant') |
@@ -256,10 +266,19 b' class APITest(NotebookTestBase):' | |||
|
256 | 266 | self.assertEqual(nb['type'], 'notebook') |
|
257 | 267 | self.assertIn('content', nb) |
|
258 | 268 | self.assertEqual(nb['format'], 'json') |
|
259 | self.assertIn('content', nb) | |
|
260 | 269 | self.assertIn('metadata', nb['content']) |
|
261 | 270 | self.assertIsInstance(nb['content']['metadata'], dict) |
|
262 | 271 | |
|
272 | def test_get_nb_no_content(self): | |
|
273 | for d, name in self.dirs_nbs: | |
|
274 | path = url_path_join(d, name + '.ipynb') | |
|
275 | nb = self.api.read(path, content=False).json() | |
|
276 | self.assertEqual(nb['name'], u'%s.ipynb' % name) | |
|
277 | self.assertEqual(nb['path'], path) | |
|
278 | self.assertEqual(nb['type'], 'notebook') | |
|
279 | self.assertIn('content', nb) | |
|
280 | self.assertEqual(nb['content'], None) | |
|
281 | ||
|
263 | 282 | def test_get_contents_no_such_file(self): |
|
264 | 283 | # Name that doesn't exist - should be a 404 |
|
265 | 284 | with assert_http_error(404): |
@@ -72,13 +72,12 b' define(function(require) {' | |||
|
72 | 72 | /** |
|
73 | 73 | * Get a file. |
|
74 | 74 | * |
|
75 | * Calls success with file JSON model, or error with error. | |
|
76 | * | |
|
77 | 75 | * @method get |
|
78 | 76 | * @param {String} path |
|
79 | 77 | * @param {Object} options |
|
80 | 78 | * type : 'notebook', 'file', or 'directory' |
|
81 | 79 | * format: 'text' or 'base64'; only relevant for type: 'file' |
|
80 | * content: true or false; // whether to include the content | |
|
82 | 81 | */ |
|
83 | 82 | Contents.prototype.get = function (path, options) { |
|
84 | 83 | /** |
@@ -94,6 +93,7 b' define(function(require) {' | |||
|
94 | 93 | var params = {}; |
|
95 | 94 | if (options.type) { params.type = options.type; } |
|
96 | 95 | if (options.format) { params.format = options.format; } |
|
96 | if (options.content === false) { params.content = '0'; } | |
|
97 | 97 | return utils.promising_ajax(url + '?' + $.param(params), settings); |
|
98 | 98 | }; |
|
99 | 99 |
General Comments 0
You need to be logged in to leave comments.
Login now