Show More
@@ -22,56 +22,65 b' HTTPError = web.HTTPError' | |||
|
22 | 22 | |
|
23 | 23 | from ..base.handlers import IPythonHandler |
|
24 | 24 | from ..utils import url_path_join |
|
25 | from urllib import quote | |
|
25 | 26 | |
|
26 | 27 | #----------------------------------------------------------------------------- |
|
27 | 28 | # Handlers |
|
28 | 29 | #----------------------------------------------------------------------------- |
|
29 | 30 | |
|
30 | 31 | |
|
32 | class NewPathHandler(IPythonHandler): | |
|
33 | ||
|
34 | @web.authenticated | |
|
35 | def get(self, notebook_path): | |
|
36 | notebook_name = self.notebook_manager.new_notebook(notebook_path) | |
|
37 | self.redirect(url_path_join(self.base_project_url,"notebooks", notebook_path, notebook_name)) | |
|
38 | ||
|
39 | ||
|
31 | 40 | class NewHandler(IPythonHandler): |
|
32 | 41 | |
|
33 | 42 | @web.authenticated |
|
34 | 43 | def get(self): |
|
35 |
notebook_ |
|
|
36 |
self.redirect(url_path_join(self.base_project_url, notebook_ |
|
|
44 | notebook_name = self.notebook_manager.new_notebook() | |
|
45 | self.redirect(url_path_join(self.base_project_url, "notebooks", notebook_name)) | |
|
37 | 46 | |
|
38 | 47 | |
|
39 | 48 | class NamedNotebookHandler(IPythonHandler): |
|
40 | 49 | |
|
41 | 50 | @web.authenticated |
|
42 |
def get(self, notebook_ |
|
|
51 | def get(self, notebook_path): | |
|
43 | 52 | nbm = self.notebook_manager |
|
44 |
|
|
|
45 | raise web.HTTPError(404, u'Notebook does not exist: %s' % notebook_id) | |
|
53 | name, path = nbm.named_notebook_path(notebook_path) | |
|
54 | if name != None: | |
|
55 | name = quote(name) | |
|
56 | self.log.info(name) | |
|
57 | if path == None: | |
|
58 | project = self.project + '/' + name | |
|
59 | else: | |
|
60 | project = self.project + '/' + path +'/'+ name | |
|
61 | #if not nbm.notebook_exists(notebook_path): | |
|
62 | # raise web.HTTPError(404, u'Notebook does not exist: %s' % notebook_path) | |
|
46 | 63 | self.write(self.render_template('notebook.html', |
|
47 |
project= |
|
|
48 |
notebook_ |
|
|
64 | project=project, | |
|
65 | notebook_path=path, | |
|
66 | notebook_name=name, | |
|
49 | 67 | kill_kernel=False, |
|
50 | 68 | mathjax_url=self.mathjax_url, |
|
51 | 69 | ) |
|
52 | 70 | ) |
|
53 | 71 | |
|
54 | 72 | |
|
55 | class NotebookRedirectHandler(IPythonHandler): | |
|
56 | ||
|
57 | @web.authenticated | |
|
58 | def get(self, notebook_name): | |
|
59 | # strip trailing .ipynb: | |
|
60 | notebook_name = os.path.splitext(notebook_name)[0] | |
|
61 | notebook_id = self.notebook_manager.rev_mapping.get(notebook_name, '') | |
|
62 | if notebook_id: | |
|
63 | url = url_path_join(self.settings.get('base_project_url', '/'), notebook_id) | |
|
64 | return self.redirect(url) | |
|
65 | else: | |
|
66 | raise HTTPError(404) | |
|
67 | ||
|
68 | ||
|
69 | 73 | class NotebookCopyHandler(IPythonHandler): |
|
70 | 74 | |
|
71 | 75 | @web.authenticated |
|
72 |
def get(self, notebook_ |
|
|
73 |
n |
|
|
74 | self.redirect(url_path_join(self.base_project_url, notebook_id)) | |
|
76 | def get(self, notebook_path=None): | |
|
77 | nbm = self.notebook_manager | |
|
78 | name, path = nbm.named_notebook_path(notebook_path) | |
|
79 | notebook_name = self.notebook_manager.copy_notebook(name, path) | |
|
80 | if path==None: | |
|
81 | self.redirect(url_path_join(self.base_project_url, "notebooks", notebook_name)) | |
|
82 | else: | |
|
83 | self.redirect(url_path_join(self.base_project_url, "notebooks", path, notebook_name)) | |
|
75 | 84 | |
|
76 | 85 | |
|
77 | 86 | #----------------------------------------------------------------------------- |
@@ -79,13 +88,11 b' class NotebookCopyHandler(IPythonHandler):' | |||
|
79 | 88 | #----------------------------------------------------------------------------- |
|
80 | 89 | |
|
81 | 90 | |
|
82 |
_notebook_ |
|
|
83 | _notebook_name_regex = r"(?P<notebook_name>.+\.ipynb)" | |
|
91 | _notebook_path_regex = r"(?P<notebook_path>.+)" | |
|
84 | 92 | |
|
85 | 93 | default_handlers = [ |
|
86 | (r"/new", NewHandler), | |
|
87 |
(r"/ |
|
|
88 |
(r"/%s" % _notebook_ |
|
|
89 |
(r"/%s |
|
|
90 | ||
|
94 | (r"/notebooks/%s/new" % _notebook_path_regex, NewPathHandler), | |
|
95 | (r"/notebooks/new", NewHandler), | |
|
96 | (r"/notebooks/%s/copy" % _notebook_path_regex, NotebookCopyHandler), | |
|
97 | (r"/notebooks/%s" % _notebook_path_regex, NamedNotebookHandler) | |
|
91 | 98 | ] |
General Comments 0
You need to be logged in to leave comments.
Login now