##// END OF EJS Templates
Merge pull request #5389 from minrk/log-files-redirect...
Brian E. Granger -
r15907:985a78fb merge
parent child Browse files
Show More
@@ -1,90 +1,90 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.handlers import IPythonHandler, notebook_path_regex, path_regex
24 24 from ..utils import url_path_join, url_escape
25 25
26 26 #-----------------------------------------------------------------------------
27 27 # Handlers
28 28 #-----------------------------------------------------------------------------
29 29
30 30
31 31 class NotebookHandler(IPythonHandler):
32 32
33 33 @web.authenticated
34 34 def get(self, path='', name=None):
35 35 """get renders the notebook template if a name is given, or
36 36 redirects to the '/files/' handler if the name is not given."""
37 37 path = path.strip('/')
38 38 nbm = self.notebook_manager
39 39 if name is None:
40 40 raise web.HTTPError(500, "This shouldn't be accessible: %s" % self.request.uri)
41 41
42 42 # a .ipynb filename was given
43 43 if not nbm.notebook_exists(name, path):
44 44 raise web.HTTPError(404, u'Notebook does not exist: %s/%s' % (path, name))
45 45 name = url_escape(name)
46 46 path = url_escape(path)
47 47 self.write(self.render_template('notebook.html',
48 48 project=self.project_dir,
49 49 notebook_path=path,
50 50 notebook_name=name,
51 51 kill_kernel=False,
52 52 mathjax_url=self.mathjax_url,
53 53 )
54 54 )
55 55
56 56 class NotebookRedirectHandler(IPythonHandler):
57 57 def get(self, path=''):
58 58 nbm = self.notebook_manager
59 59 if nbm.path_exists(path):
60 60 # it's a *directory*, redirect to /tree
61 61 url = url_path_join(self.base_url, 'tree', path)
62 62 else:
63 63 # otherwise, redirect to /files
64 64 if '/files/' in path:
65 65 # redirect without files/ iff it would 404
66 66 # this preserves pre-2.0-style 'files/' links
67 67 # FIXME: this is hardcoded based on notebook_path,
68 68 # but so is the files handler itself,
69 69 # so it should work until both are cleaned up.
70 70 parts = path.split('/')
71 71 files_path = os.path.join(nbm.notebook_dir, *parts)
72 self.log.warn("filespath: %s", files_path)
73 72 if not os.path.exists(files_path):
73 self.log.warn("Deprecated files/ URL: %s", path)
74 74 path = path.replace('/files/', '/', 1)
75 75
76 76 url = url_path_join(self.base_url, 'files', path)
77 77 url = url_escape(url)
78 78 self.log.debug("Redirecting %s to %s", self.request.path, url)
79 79 self.redirect(url)
80 80
81 81 #-----------------------------------------------------------------------------
82 82 # URL to handler mappings
83 83 #-----------------------------------------------------------------------------
84 84
85 85
86 86 default_handlers = [
87 87 (r"/notebooks%s" % notebook_path_regex, NotebookHandler),
88 88 (r"/notebooks%s" % path_regex, NotebookRedirectHandler),
89 89 ]
90 90
General Comments 0
You need to be logged in to leave comments. Login now