##// END OF EJS Templates
allow slash in root->tree redirect...
MinRK -
Show More
@@ -1,84 +1,84 b''
1 """Tornado handlers for the tree view."""
1 """Tornado handlers for the tree 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 from tornado import web
6 from tornado import web
7 from ..base.handlers import IPythonHandler, notebook_path_regex, path_regex
7 from ..base.handlers import IPythonHandler, notebook_path_regex, path_regex
8 from ..utils import url_path_join, url_escape
8 from ..utils import url_path_join, url_escape
9
9
10
10
11 class TreeHandler(IPythonHandler):
11 class TreeHandler(IPythonHandler):
12 """Render the tree view, listing notebooks, clusters, etc."""
12 """Render the tree view, listing notebooks, clusters, etc."""
13
13
14 def generate_breadcrumbs(self, path):
14 def generate_breadcrumbs(self, path):
15 breadcrumbs = [(url_escape(url_path_join(self.base_url, 'tree')), '')]
15 breadcrumbs = [(url_escape(url_path_join(self.base_url, 'tree')), '')]
16 comps = path.split('/')
16 comps = path.split('/')
17 ncomps = len(comps)
17 ncomps = len(comps)
18 for i in range(ncomps):
18 for i in range(ncomps):
19 if comps[i]:
19 if comps[i]:
20 link = url_escape(url_path_join(self.base_url, 'tree', *comps[0:i+1]))
20 link = url_escape(url_path_join(self.base_url, 'tree', *comps[0:i+1]))
21 breadcrumbs.append((link, comps[i]))
21 breadcrumbs.append((link, comps[i]))
22 return breadcrumbs
22 return breadcrumbs
23
23
24 def generate_page_title(self, path):
24 def generate_page_title(self, path):
25 comps = path.split('/')
25 comps = path.split('/')
26 if len(comps) > 3:
26 if len(comps) > 3:
27 for i in range(len(comps)-2):
27 for i in range(len(comps)-2):
28 comps.pop(0)
28 comps.pop(0)
29 page_title = url_path_join(*comps)
29 page_title = url_path_join(*comps)
30 if page_title:
30 if page_title:
31 return page_title+'/'
31 return page_title+'/'
32 else:
32 else:
33 return 'Home'
33 return 'Home'
34
34
35 @web.authenticated
35 @web.authenticated
36 def get(self, path='', name=None):
36 def get(self, path='', name=None):
37 path = path.strip('/')
37 path = path.strip('/')
38 cm = self.contents_manager
38 cm = self.contents_manager
39 if name is not None:
39 if name is not None:
40 # is a notebook, redirect to notebook handler
40 # is a notebook, redirect to notebook handler
41 url = url_escape(url_path_join(
41 url = url_escape(url_path_join(
42 self.base_url, 'notebooks', path, name
42 self.base_url, 'notebooks', path, name
43 ))
43 ))
44 self.log.debug("Redirecting %s to %s", self.request.path, url)
44 self.log.debug("Redirecting %s to %s", self.request.path, url)
45 self.redirect(url)
45 self.redirect(url)
46 else:
46 else:
47 if not cm.path_exists(path=path):
47 if not cm.path_exists(path=path):
48 # Directory is hidden or does not exist.
48 # Directory is hidden or does not exist.
49 raise web.HTTPError(404)
49 raise web.HTTPError(404)
50 elif cm.is_hidden(path):
50 elif cm.is_hidden(path):
51 self.log.info("Refusing to serve hidden directory, via 404 Error")
51 self.log.info("Refusing to serve hidden directory, via 404 Error")
52 raise web.HTTPError(404)
52 raise web.HTTPError(404)
53 breadcrumbs = self.generate_breadcrumbs(path)
53 breadcrumbs = self.generate_breadcrumbs(path)
54 page_title = self.generate_page_title(path)
54 page_title = self.generate_page_title(path)
55 self.write(self.render_template('tree.html',
55 self.write(self.render_template('tree.html',
56 page_title=page_title,
56 page_title=page_title,
57 notebook_path=path,
57 notebook_path=path,
58 breadcrumbs=breadcrumbs
58 breadcrumbs=breadcrumbs
59 ))
59 ))
60
60
61
61
62 class TreeRedirectHandler(IPythonHandler):
62 class TreeRedirectHandler(IPythonHandler):
63 """Redirect a request to the corresponding tree URL"""
63 """Redirect a request to the corresponding tree URL"""
64
64
65 @web.authenticated
65 @web.authenticated
66 def get(self, path=''):
66 def get(self, path=''):
67 url = url_escape(url_path_join(
67 url = url_escape(url_path_join(
68 self.base_url, 'tree', path.strip('/')
68 self.base_url, 'tree', path.strip('/')
69 ))
69 ))
70 self.log.debug("Redirecting %s to %s", self.request.path, url)
70 self.log.debug("Redirecting %s to %s", self.request.path, url)
71 self.redirect(url)
71 self.redirect(url)
72
72
73
73
74 #-----------------------------------------------------------------------------
74 #-----------------------------------------------------------------------------
75 # URL to handler mappings
75 # URL to handler mappings
76 #-----------------------------------------------------------------------------
76 #-----------------------------------------------------------------------------
77
77
78
78
79 default_handlers = [
79 default_handlers = [
80 (r"/tree%s" % notebook_path_regex, TreeHandler),
80 (r"/tree%s" % notebook_path_regex, TreeHandler),
81 (r"/tree%s" % path_regex, TreeHandler),
81 (r"/tree%s" % path_regex, TreeHandler),
82 (r"/tree", TreeHandler),
82 (r"/tree", TreeHandler),
83 (r"", TreeRedirectHandler),
83 (r"/?", TreeRedirectHandler),
84 ]
84 ]
General Comments 0
You need to be logged in to leave comments. Login now