Show More
@@ -1,56 +1,56 b'' | |||
|
1 | 1 | """Tornado handlers for the live notebook view.""" |
|
2 | 2 | |
|
3 | 3 | # Copyright (c) IPython Development Team. |
|
4 | 4 | # Distributed under the terms of the Modified BSD License. |
|
5 | 5 | |
|
6 | 6 | import os |
|
7 | 7 | from tornado import web |
|
8 | 8 | HTTPError = web.HTTPError |
|
9 | 9 | |
|
10 | 10 | from ..base.handlers import ( |
|
11 | 11 | IPythonHandler, FilesRedirectHandler, path_regex, |
|
12 | 12 | ) |
|
13 | 13 | from ..utils import url_escape |
|
14 | 14 | |
|
15 | 15 | |
|
16 | 16 | class NotebookHandler(IPythonHandler): |
|
17 | 17 | |
|
18 | 18 | @web.authenticated |
|
19 | 19 | def get(self, path): |
|
20 | 20 | """get renders the notebook template if a name is given, or |
|
21 | 21 | redirects to the '/files/' handler if the name is not given.""" |
|
22 | 22 | path = path.strip('/') |
|
23 | 23 | cm = self.contents_manager |
|
24 | 24 | |
|
25 | 25 | # will raise 404 on not found |
|
26 | 26 | try: |
|
27 | 27 | model = cm.get(path, content=False) |
|
28 | 28 | except web.HTTPError as e: |
|
29 | if e.code == 404 and 'files' in path.split('/'): | |
|
29 | if e.status_code == 404 and 'files' in path.split('/'): | |
|
30 | 30 | # 404, but '/files/' in URL, let FilesRedirect take care of it |
|
31 | 31 | return FilesRedirectHandler.get(self, path) |
|
32 | 32 | else: |
|
33 | 33 | raise |
|
34 | 34 | if model['type'] != 'notebook': |
|
35 | 35 | # not a notebook, redirect to files |
|
36 | 36 | return FilesRedirectHandler.get(self, path) |
|
37 | 37 | name = url_escape(path.rsplit('/', 1)[-1]) |
|
38 | 38 | path = url_escape(path) |
|
39 | 39 | self.write(self.render_template('notebook.html', |
|
40 | 40 | notebook_path=path, |
|
41 | 41 | notebook_name=name, |
|
42 | 42 | kill_kernel=False, |
|
43 | 43 | mathjax_url=self.mathjax_url, |
|
44 | 44 | ) |
|
45 | 45 | ) |
|
46 | 46 | |
|
47 | 47 | |
|
48 | 48 | #----------------------------------------------------------------------------- |
|
49 | 49 | # URL to handler mappings |
|
50 | 50 | #----------------------------------------------------------------------------- |
|
51 | 51 | |
|
52 | 52 | |
|
53 | 53 | default_handlers = [ |
|
54 | 54 | (r"/notebooks%s" % path_regex, NotebookHandler), |
|
55 | 55 | ] |
|
56 | 56 |
General Comments 0
You need to be logged in to leave comments.
Login now