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