handlers.py
49 lines
| 1.4 KiB
| text/x-python
|
PythonLexer
MinRK
|
r17533 | """Tornado handlers for the live notebook view.""" | ||
Brian E. Granger
|
r10641 | |||
MinRK
|
r17533 | # Copyright (c) IPython Development Team. | ||
# Distributed under the terms of the Modified BSD License. | ||||
Brian E. Granger
|
r10641 | |||
MinRK
|
r13563 | import os | ||
Brian E. Granger
|
r10641 | from tornado import web | ||
Brian E. Granger
|
r10642 | HTTPError = web.HTTPError | ||
Brian E. Granger
|
r10641 | |||
MinRK
|
r17533 | from ..base.handlers import ( | ||
IPythonHandler, FilesRedirectHandler, | ||||
notebook_path_regex, path_regex, | ||||
) | ||||
from ..utils import url_escape | ||||
Brian E. Granger
|
r10641 | |||
Zachary Sailer
|
r13016 | class NotebookHandler(IPythonHandler): | ||
Brian E. Granger
|
r10641 | |||
@web.authenticated | ||||
Min RK
|
r18758 | def get(self, path): | ||
Paul Ivanov
|
r13029 | """get renders the notebook template if a name is given, or | ||
redirects to the '/files/' handler if the name is not given.""" | ||||
MinRK
|
r13117 | path = path.strip('/') | ||
MinRK
|
r17524 | cm = self.contents_manager | ||
MinRK
|
r13073 | |||
MinRK
|
r13067 | # a .ipynb filename was given | ||
MinRK
|
r18749 | if not cm.file_exists(path): | ||
raise web.HTTPError(404, u'Notebook does not exist: %s' % path) | ||||
name = url_escape(path.rsplit('/', 1)[-1]) | ||||
MinRK
|
r13068 | path = url_escape(path) | ||
MinRK
|
r13067 | self.write(self.render_template('notebook.html', | ||
notebook_path=path, | ||||
notebook_name=name, | ||||
kill_kernel=False, | ||||
mathjax_url=self.mathjax_url, | ||||
) | ||||
) | ||||
Zachary Sailer
|
r13016 | |||
Brian E. Granger
|
r10641 | |||
Brian E. Granger
|
r10647 | #----------------------------------------------------------------------------- | ||
# URL to handler mappings | ||||
#----------------------------------------------------------------------------- | ||||
default_handlers = [ | ||||
Thomas Kluyver
|
r13916 | (r"/notebooks%s" % notebook_path_regex, NotebookHandler), | ||
MinRK
|
r17533 | (r"/notebooks%s" % path_regex, FilesRedirectHandler), | ||
Zachary Sailer
|
r13033 | ] | ||