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