##// END OF EJS Templates
Another variation of the dashboard page title.
Brian E. Granger -
Show More
@@ -1,101 +1,100 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
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_project_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_project_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 comps.insert(0, '...')
48 47 page_title = url_escape(url_path_join(*comps))
49 48 if page_title:
50 return '/'+page_title+'/'
49 return page_title+'/'
51 50 else:
52 return '/'
51 return 'Home'
53 52
54 53 @web.authenticated
55 54 def get(self, path='', name=None):
56 55 path = path.strip('/')
57 56 nbm = self.notebook_manager
58 57 if name is not None:
59 58 # is a notebook, redirect to notebook handler
60 59 url = url_escape(url_path_join(
61 60 self.base_project_url, 'notebooks', path, name
62 61 ))
63 62 self.log.debug("Redirecting %s to %s", self.request.path, url)
64 63 self.redirect(url)
65 64 else:
66 65 if not nbm.path_exists(path=path):
67 66 # no such directory, 404
68 67 raise web.HTTPError(404)
69 68 breadcrumbs = self.generate_breadcrumbs(path)
70 69 page_title = self.generate_page_title(path)
71 70 self.write(self.render_template('tree.html',
72 71 project=self.project_dir,
73 72 page_title=page_title,
74 73 notebook_path=path,
75 74 breadcrumbs=breadcrumbs
76 75 ))
77 76
78 77
79 78 class TreeRedirectHandler(IPythonHandler):
80 79 """Redirect a request to the corresponding tree URL"""
81 80
82 81 @web.authenticated
83 82 def get(self, path=''):
84 83 url = url_escape(url_path_join(
85 84 self.base_project_url, 'tree', path.strip('/')
86 85 ))
87 86 self.log.debug("Redirecting %s to %s", self.request.path, url)
88 87 self.redirect(url)
89 88
90 89
91 90 #-----------------------------------------------------------------------------
92 91 # URL to handler mappings
93 92 #-----------------------------------------------------------------------------
94 93
95 94
96 95 default_handlers = [
97 96 (r"/tree%s" % notebook_path_regex, TreeHandler),
98 97 (r"/tree%s" % path_regex, TreeHandler),
99 98 (r"/tree", TreeHandler),
100 99 (r"/", TreeRedirectHandler),
101 100 ]
General Comments 0
You need to be logged in to leave comments. Login now