##// END OF EJS Templates
Backport PR #6117: Remove / from route of TreeRedirectHandler....
MinRK -
Show More
@@ -1,103 +1,103 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 import os
19 19
20 20 from tornado import web
21 21 from ..base.handlers import IPythonHandler, notebook_path_regex, path_regex
22 22 from ..utils import url_path_join, path2url, url2path, url_escape, is_hidden
23 23
24 24 #-----------------------------------------------------------------------------
25 25 # Handlers
26 26 #-----------------------------------------------------------------------------
27 27
28 28
29 29 class TreeHandler(IPythonHandler):
30 30 """Render the tree view, listing notebooks, clusters, etc."""
31 31
32 32 def generate_breadcrumbs(self, path):
33 33 breadcrumbs = [(url_escape(url_path_join(self.base_url, 'tree')), '')]
34 34 comps = path.split('/')
35 35 ncomps = len(comps)
36 36 for i in range(ncomps):
37 37 if comps[i]:
38 38 link = url_escape(url_path_join(self.base_url, 'tree', *comps[0:i+1]))
39 39 breadcrumbs.append((link, comps[i]))
40 40 return breadcrumbs
41 41
42 42 def generate_page_title(self, path):
43 43 comps = path.split('/')
44 44 if len(comps) > 3:
45 45 for i in range(len(comps)-2):
46 46 comps.pop(0)
47 47 page_title = url_path_join(*comps)
48 48 if page_title:
49 49 return page_title+'/'
50 50 else:
51 51 return 'Home'
52 52
53 53 @web.authenticated
54 54 def get(self, path='', name=None):
55 55 path = path.strip('/')
56 56 nbm = self.notebook_manager
57 57 if name is not None:
58 58 # is a notebook, redirect to notebook handler
59 59 url = url_escape(url_path_join(
60 60 self.base_url, 'notebooks', path, name
61 61 ))
62 62 self.log.debug("Redirecting %s to %s", self.request.path, url)
63 63 self.redirect(url)
64 64 else:
65 65 if not nbm.path_exists(path=path):
66 66 # Directory is hidden or does not exist.
67 67 raise web.HTTPError(404)
68 68 elif nbm.is_hidden(path):
69 69 self.log.info("Refusing to serve hidden directory, via 404 Error")
70 70 raise web.HTTPError(404)
71 71 breadcrumbs = self.generate_breadcrumbs(path)
72 72 page_title = self.generate_page_title(path)
73 73 self.write(self.render_template('tree.html',
74 74 project=self.project_dir,
75 75 page_title=page_title,
76 76 notebook_path=path,
77 77 breadcrumbs=breadcrumbs
78 78 ))
79 79
80 80
81 81 class TreeRedirectHandler(IPythonHandler):
82 82 """Redirect a request to the corresponding tree URL"""
83 83
84 84 @web.authenticated
85 85 def get(self, path=''):
86 86 url = url_escape(url_path_join(
87 87 self.base_url, 'tree', path.strip('/')
88 88 ))
89 89 self.log.debug("Redirecting %s to %s", self.request.path, url)
90 90 self.redirect(url)
91 91
92 92
93 93 #-----------------------------------------------------------------------------
94 94 # URL to handler mappings
95 95 #-----------------------------------------------------------------------------
96 96
97 97
98 98 default_handlers = [
99 99 (r"/tree%s" % notebook_path_regex, TreeHandler),
100 100 (r"/tree%s" % path_regex, TreeHandler),
101 101 (r"/tree", TreeHandler),
102 (r"/", TreeRedirectHandler),
102 (r"", TreeRedirectHandler),
103 103 ]
General Comments 0
You need to be logged in to leave comments. Login now