##// END OF EJS Templates
Fixing url join problems.
Brian E. Granger -
Show More
@@ -1,75 +1,75 b''
1 1 """Tornado handlers for the live notebook 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
19 19 import os
20 20 from tornado import web
21 21 HTTPError = web.HTTPError
22 22
23 23 from .base import IPythonHandler, authenticate_unless_readonly
24 24 from ..utils import url_path_join
25 25
26 26 #-----------------------------------------------------------------------------
27 27 # Handlers
28 28 #-----------------------------------------------------------------------------
29 29
30 30
31 31 class NewHandler(IPythonHandler):
32 32
33 33 @web.authenticated
34 34 def get(self):
35 35 notebook_id = self.notebook_manager.new_notebook()
36 self.redirect('/' + url_path_join(self.base_project_url, notebook_id))
36 self.redirect(url_path_join(self.base_project_url, notebook_id))
37 37
38 38
39 39 class NamedNotebookHandler(IPythonHandler):
40 40
41 41 @authenticate_unless_readonly
42 42 def get(self, notebook_id):
43 43 nbm = self.notebook_manager
44 44 if not nbm.notebook_exists(notebook_id):
45 45 raise web.HTTPError(404, u'Notebook does not exist: %s' % notebook_id)
46 46 self.write(self.render_template('notebook.html',
47 47 project=self.project,
48 48 notebook_id=notebook_id,
49 49 kill_kernel=False,
50 50 mathjax_url=self.mathjax_url,
51 51 )
52 52 )
53 53
54 54
55 55 class NotebookRedirectHandler(IPythonHandler):
56 56
57 57 @authenticate_unless_readonly
58 58 def get(self, notebook_name):
59 59 # strip trailing .ipynb:
60 60 notebook_name = os.path.splitext(notebook_name)[0]
61 61 notebook_id = self.notebook_manager.rev_mapping.get(notebook_name, '')
62 62 if notebook_id:
63 url = self.settings.get('base_project_url', '/') + notebook_id
63 url = url_path_join(self.settings.get('base_project_url', '/'), notebook_id)
64 64 return self.redirect(url)
65 65 else:
66 66 raise HTTPError(404)
67 67
68 68
69 69 class NotebookCopyHandler(IPythonHandler):
70 70
71 71 @web.authenticated
72 72 def get(self, notebook_id):
73 73 notebook_id = self.notebook_manager.copy_notebook(notebook_id)
74 self.redirect('/'+url_path_join(self.base_project_url, notebook_id))
74 self.redirect(url_path_join(self.base_project_url, notebook_id))
75 75
@@ -1,31 +1,32 b''
1 1 """Notebook related utilities
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
19 19 def url_path_join(*pieces):
20 20 """Join components of url into a relative url
21 21
22 22 Use to prevent double slash when joining subpath. This will leave the
23 23 initial and final / in place
24 24 """
25 25 initial = pieces[0].startswith('/')
26 26 final = pieces[-1].endswith('/')
27 27 striped = [s.strip('/') for s in pieces]
28 28 result = '/'.join(s for s in striped if s)
29 29 if initial: result = '/' + result
30 30 if final: result = result + '/'
31 if result == '//': result = '/'
31 32 return result
General Comments 0
You need to be logged in to leave comments. Login now