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