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