Show More
@@ -17,10 +17,10 b' Authors:' | |||||
17 | #----------------------------------------------------------------------------- |
|
17 | #----------------------------------------------------------------------------- | |
18 |
|
18 | |||
19 | import os |
|
19 | import os | |
|
20 | import json | |||
|
21 | ||||
20 | from tornado import web |
|
22 | from tornado import web | |
21 | HTTPError = web.HTTPError |
|
23 | HTTPError = web.HTTPError | |
22 | from zmq.utils import jsonapi |
|
|||
23 |
|
||||
24 |
|
24 | |||
25 | from ..base.handlers import IPythonHandler |
|
25 | from ..base.handlers import IPythonHandler | |
26 | from ..services.notebooks.handlers import _notebook_path_regex, _path_regex |
|
26 | from ..services.notebooks.handlers import _notebook_path_regex, _path_regex | |
@@ -35,32 +35,13 b' from urllib import quote' | |||||
35 | class NotebookHandler(IPythonHandler): |
|
35 | class NotebookHandler(IPythonHandler): | |
36 |
|
36 | |||
37 | @web.authenticated |
|
37 | @web.authenticated | |
38 | def post(self): |
|
|||
39 | """post either creates a new notebook if no json data is |
|
|||
40 | sent to the server, or copies the data and returns a |
|
|||
41 | copied notebook.""" |
|
|||
42 | nbm = self.notebook_manager |
|
|||
43 | data=self.request.body |
|
|||
44 | if data: |
|
|||
45 | data = jsonapi.loads(data) |
|
|||
46 | notebook_name = nbm.copy_notebook(data['name']) |
|
|||
47 | else: |
|
|||
48 | notebook_name = nbm.new_notebook() |
|
|||
49 | self.finish(jsonapi.dumps({"name": notebook_name})) |
|
|||
50 |
|
||||
51 |
|
||||
52 | class NamedNotebookHandler(IPythonHandler): |
|
|||
53 |
|
||||
54 | @web.authenticated |
|
|||
55 | def get(self, path='', name=None): |
|
38 | def get(self, path='', name=None): | |
56 | """get renders the notebook template if a name is given, or |
|
39 | """get renders the notebook template if a name is given, or | |
57 | redirects to the '/files/' handler if the name is not given.""" |
|
40 | redirects to the '/files/' handler if the name is not given.""" | |
58 | nbm = self.notebook_manager |
|
41 | nbm = self.notebook_manager | |
59 | if name is None: |
|
42 | if name is None: | |
60 | url = url_path_join(self.base_project_url, 'files', path) |
|
43 | raise web.HTTPError(500, "This shouldn't be accessible: %s" % self.request.uri) | |
61 | self.redirect(url) |
|
44 | ||
62 | return |
|
|||
63 |
|
||||
64 | # a .ipynb filename was given |
|
45 | # a .ipynb filename was given | |
65 | if not nbm.notebook_exists(name, path): |
|
46 | if not nbm.notebook_exists(name, path): | |
66 | raise web.HTTPError(404, u'Notebook does not exist: %s/%s' % (path, name)) |
|
47 | raise web.HTTPError(404, u'Notebook does not exist: %s/%s' % (path, name)) | |
@@ -75,20 +56,17 b' class NamedNotebookHandler(IPythonHandler):' | |||||
75 | ) |
|
56 | ) | |
76 | ) |
|
57 | ) | |
77 |
|
58 | |||
78 | @web.authenticated |
|
59 | class NotebookRedirectHandler(IPythonHandler): | |
79 |
def |
|
60 | def get(self, path=''): | |
80 | """post either creates a new notebook if no json data is |
|
|||
81 | sent to the server, or copies the data and returns a |
|
|||
82 | copied notebook in the location given by 'notebook_path.""" |
|
|||
83 | nbm = self.notebook_manager |
|
61 | nbm = self.notebook_manager | |
84 | data = self.request.body |
|
62 | if nbm.path_exists(path): | |
85 | if data: |
|
63 | # it's a *directory*, redirect to /tree | |
86 | data = jsonapi.loads(data) |
|
64 | url = url_path_join(self.base_project_url, 'tree', path) | |
87 | notebook_name = nbm.copy_notebook(data['name'], notebook_path) |
|
|||
88 | else: |
|
65 | else: | |
89 | notebook_name = nbm.new_notebook(notebook_path) |
|
66 | # otherwise, redirect to /files | |
90 | self.finish(jsonapi.dumps({"name": notebook_name})) |
|
67 | # TODO: This should check if it's actually a file | |
91 |
|
68 | url = url_path_join(self.base_project_url, 'files', path) | ||
|
69 | self.redirect(url) | |||
92 |
|
70 | |||
93 | #----------------------------------------------------------------------------- |
|
71 | #----------------------------------------------------------------------------- | |
94 | # URL to handler mappings |
|
72 | # URL to handler mappings | |
@@ -96,8 +74,7 b' class NamedNotebookHandler(IPythonHandler):' | |||||
96 |
|
74 | |||
97 |
|
75 | |||
98 | default_handlers = [ |
|
76 | default_handlers = [ | |
99 |
(r"/notebooks/?%s" % _notebook_path_regex, |
|
77 | (r"/notebooks/?%s" % _notebook_path_regex, NotebookHandler), | |
100 |
(r"/notebooks/?%s" % _path_regex, |
|
78 | (r"/notebooks/?%s" % _path_regex, NotebookRedirectHandler), | |
101 | (r"/notebooks/?", NotebookHandler), |
|
|||
102 | ] |
|
79 | ] | |
103 |
|
80 |
General Comments 0
You need to be logged in to leave comments.
Login now