##// END OF EJS Templates
Merge pull request #5769 from spenczar/no_urlescaping_title_tag...
Min RK -
r16528:8462276d merge
parent child Browse files
Show More
@@ -1,101 +1,101 b''
1 """Tornado handlers for the tree view.
1 """Tornado handlers for the tree view.
2
2
3 Authors:
3 Authors:
4
4
5 * Brian Granger
5 * Brian Granger
6 """
6 """
7
7
8 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2011 The IPython Development Team
9 # Copyright (C) 2011 The IPython Development Team
10 #
10 #
11 # Distributed under the terms of the BSD License. The full license is in
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
12 # the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14
14
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 # Imports
16 # Imports
17 #-----------------------------------------------------------------------------
17 #-----------------------------------------------------------------------------
18 from tornado import web
18 from tornado import web
19 from ..base.handlers import IPythonHandler, notebook_path_regex, path_regex
19 from ..base.handlers import IPythonHandler, notebook_path_regex, path_regex
20 from ..utils import url_path_join, url_escape
20 from ..utils import url_path_join, url_escape
21
21
22 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
23 # Handlers
23 # Handlers
24 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
25
25
26
26
27 class TreeHandler(IPythonHandler):
27 class TreeHandler(IPythonHandler):
28 """Render the tree view, listing notebooks, clusters, etc."""
28 """Render the tree view, listing notebooks, clusters, etc."""
29
29
30 def generate_breadcrumbs(self, path):
30 def generate_breadcrumbs(self, path):
31 breadcrumbs = [(url_escape(url_path_join(self.base_url, 'tree')), '')]
31 breadcrumbs = [(url_escape(url_path_join(self.base_url, 'tree')), '')]
32 comps = path.split('/')
32 comps = path.split('/')
33 ncomps = len(comps)
33 ncomps = len(comps)
34 for i in range(ncomps):
34 for i in range(ncomps):
35 if comps[i]:
35 if comps[i]:
36 link = url_escape(url_path_join(self.base_url, 'tree', *comps[0:i+1]))
36 link = url_escape(url_path_join(self.base_url, 'tree', *comps[0:i+1]))
37 breadcrumbs.append((link, comps[i]))
37 breadcrumbs.append((link, comps[i]))
38 return breadcrumbs
38 return breadcrumbs
39
39
40 def generate_page_title(self, path):
40 def generate_page_title(self, path):
41 comps = path.split('/')
41 comps = path.split('/')
42 if len(comps) > 3:
42 if len(comps) > 3:
43 for i in range(len(comps)-2):
43 for i in range(len(comps)-2):
44 comps.pop(0)
44 comps.pop(0)
45 page_title = url_escape(url_path_join(*comps))
45 page_title = url_path_join(*comps)
46 if page_title:
46 if page_title:
47 return page_title+'/'
47 return page_title+'/'
48 else:
48 else:
49 return 'Home'
49 return 'Home'
50
50
51 @web.authenticated
51 @web.authenticated
52 def get(self, path='', name=None):
52 def get(self, path='', name=None):
53 path = path.strip('/')
53 path = path.strip('/')
54 nbm = self.notebook_manager
54 nbm = self.notebook_manager
55 if name is not None:
55 if name is not None:
56 # is a notebook, redirect to notebook handler
56 # is a notebook, redirect to notebook handler
57 url = url_escape(url_path_join(
57 url = url_escape(url_path_join(
58 self.base_url, 'notebooks', path, name
58 self.base_url, 'notebooks', path, name
59 ))
59 ))
60 self.log.debug("Redirecting %s to %s", self.request.path, url)
60 self.log.debug("Redirecting %s to %s", self.request.path, url)
61 self.redirect(url)
61 self.redirect(url)
62 else:
62 else:
63 if not nbm.path_exists(path=path):
63 if not nbm.path_exists(path=path):
64 # Directory is hidden or does not exist.
64 # Directory is hidden or does not exist.
65 raise web.HTTPError(404)
65 raise web.HTTPError(404)
66 elif nbm.is_hidden(path):
66 elif nbm.is_hidden(path):
67 self.log.info("Refusing to serve hidden directory, via 404 Error")
67 self.log.info("Refusing to serve hidden directory, via 404 Error")
68 raise web.HTTPError(404)
68 raise web.HTTPError(404)
69 breadcrumbs = self.generate_breadcrumbs(path)
69 breadcrumbs = self.generate_breadcrumbs(path)
70 page_title = self.generate_page_title(path)
70 page_title = self.generate_page_title(path)
71 self.write(self.render_template('tree.html',
71 self.write(self.render_template('tree.html',
72 project=self.project_dir,
72 project=self.project_dir,
73 page_title=page_title,
73 page_title=page_title,
74 notebook_path=path,
74 notebook_path=path,
75 breadcrumbs=breadcrumbs
75 breadcrumbs=breadcrumbs
76 ))
76 ))
77
77
78
78
79 class TreeRedirectHandler(IPythonHandler):
79 class TreeRedirectHandler(IPythonHandler):
80 """Redirect a request to the corresponding tree URL"""
80 """Redirect a request to the corresponding tree URL"""
81
81
82 @web.authenticated
82 @web.authenticated
83 def get(self, path=''):
83 def get(self, path=''):
84 url = url_escape(url_path_join(
84 url = url_escape(url_path_join(
85 self.base_url, 'tree', path.strip('/')
85 self.base_url, 'tree', path.strip('/')
86 ))
86 ))
87 self.log.debug("Redirecting %s to %s", self.request.path, url)
87 self.log.debug("Redirecting %s to %s", self.request.path, url)
88 self.redirect(url)
88 self.redirect(url)
89
89
90
90
91 #-----------------------------------------------------------------------------
91 #-----------------------------------------------------------------------------
92 # URL to handler mappings
92 # URL to handler mappings
93 #-----------------------------------------------------------------------------
93 #-----------------------------------------------------------------------------
94
94
95
95
96 default_handlers = [
96 default_handlers = [
97 (r"/tree%s" % notebook_path_regex, TreeHandler),
97 (r"/tree%s" % notebook_path_regex, TreeHandler),
98 (r"/tree%s" % path_regex, TreeHandler),
98 (r"/tree%s" % path_regex, TreeHandler),
99 (r"/tree", TreeHandler),
99 (r"/tree", TreeHandler),
100 (r"/", TreeRedirectHandler),
100 (r"/", TreeRedirectHandler),
101 ]
101 ]
General Comments 0
You need to be logged in to leave comments. Login now