##// END OF EJS Templates
redirect url after notebook rename
Zachary Sailer -
Show More
@@ -1,105 +1,104 b''
1 1 """Tornado handlers for the notebooks web service.
2 2
3 3 Authors:
4 4
5 5 * Zach Sailer
6 6 """
7 7
8 8 #-----------------------------------------------------------------------------
9 9 # Copyright (C) 2008-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 from tornado import web
20 20
21 21 from zmq.utils import jsonapi
22 22
23 23 from IPython.utils.jsonutil import date_default
24
25 24 from ...base.handlers import IPythonHandler, authenticate_unless_readonly
26 25
27 26 #-----------------------------------------------------------------------------
28 27 # Session web service handlers
29 28 #-----------------------------------------------------------------------------
30 29
31 30
32 31
33 32 class SessionRootHandler(IPythonHandler):
34 33
35 34 @authenticate_unless_readonly
36 35 def get(self):
37 36 sm = self.session_manager
38 37 nbm = self.notebook_manager
39 38 km = self.kernel_manager
40 39 sessions = sm.list_sessions()
41 40 self.finish(jsonapi.dumps(sessions))
42 41
43 42 @web.authenticated
44 43 def post(self):
45 44 sm = self.session_manager
46 45 nbm = self.notebook_manager
47 46 km = self.kernel_manager
48 47 notebook_path = self.get_argument('notebook_path', default=None)
49 48 notebook_name, path = nbm.named_notebook_path(notebook_path)
50 49 session_id, model = sm.get_session(notebook_name, path)
51 50 if model == None:
52 51 kernel_id = km.start_kernel()
53 52 kernel = km.kernel_model(kernel_id, self.ws_url)
54 53 model = sm.session_model(session_id, notebook_name, path, kernel)
55 54 self.finish(jsonapi.dumps(model))
56 55
57 56 class SessionHandler(IPythonHandler):
58 57
59 58 SUPPORTED_METHODS = ('GET', 'PATCH', 'DELETE')
60 59
61 60 @authenticate_unless_readonly
62 61 def get(self, session_id):
63 62 sm = self.session_manager
64 63 model = sm.get_session_from_id(session_id)
65 64 self.finish(jsonapi.dumps(model))
66 65
67 66 @web.authenticated
68 67 def patch(self, session_id):
69 68 sm = self.session_manager
70 69 nbm = self.notebook_manager
71 70 km = self.kernel_manager
72 71 notebook_path = self.request.body
73 72 notebook_name, path = nbm.named_notebook_path(notebook_path)
74 73 kernel_id = sm.get_kernel_from_session(session_id)
75 74 kernel = km.kernel_model(kernel_id, self.ws_url)
76 75 sm.delete_mapping_for_session(session_id)
77 76 model = sm.session_model(session_id, notebook_name, path, kernel)
78 77 self.finish(jsonapi.dumps(model))
79 78
80 79 @web.authenticated
81 80 def delete(self, session_id):
82 81 sm = self.session_manager
83 82 nbm = self.notebook_manager
84 83 km = self.kernel_manager
85 84 kernel_id = sm.get_kernel_from_session(session_id)
86 85 km.shutdown_kernel(kernel_id)
87 86 sm.delete_mapping_for_session(session_id)
88 87 self.set_status(204)
89 88 self.finish()
90 89
91 90
92 91 #-----------------------------------------------------------------------------
93 92 # URL to handler mappings
94 93 #-----------------------------------------------------------------------------
95 94
96 95 _session_id_regex = r"(?P<session_id>\w+-\w+-\w+-\w+-\w+)"
97 96
98 97 default_handlers = [
99 98 (r"api/sessions/%s" % _session_id_regex, SessionHandler),
100 99 (r"api/sessions", SessionRootHandler)
101 100 ]
102 101
103 102
104 103
105 104
@@ -1,161 +1,166 b''
1 1 //----------------------------------------------------------------------------
2 2 // Copyright (C) 2008-2011 The IPython Development Team
3 3 //
4 4 // Distributed under the terms of the BSD License. The full license is in
5 5 // the file COPYING, distributed as part of this software.
6 6 //----------------------------------------------------------------------------
7 7
8 8 //============================================================================
9 9 // SaveWidget
10 10 //============================================================================
11 11
12 12 var IPython = (function (IPython) {
13 13 "use strict";
14 14
15 15 var utils = IPython.utils;
16 16
17 17 var SaveWidget = function (selector) {
18 18 this.selector = selector;
19 19 if (this.selector !== undefined) {
20 20 this.element = $(selector);
21 21 this.style();
22 22 this.bind_events();
23 23 }
24 24 };
25 25
26 26
27 27 SaveWidget.prototype.style = function () {
28 28 };
29 29
30 30
31 31 SaveWidget.prototype.bind_events = function () {
32 32 var that = this;
33 33 this.element.find('span#notebook_name').click(function () {
34 34 that.rename_notebook();
35 35 });
36 36 this.element.find('span#notebook_name').hover(function () {
37 37 $(this).addClass("ui-state-hover");
38 38 }, function () {
39 39 $(this).removeClass("ui-state-hover");
40 40 });
41 41 $([IPython.events]).on('notebook_loaded.Notebook', function () {
42 42 that.update_notebook_name();
43 43 that.update_document_title();
44 44 });
45 45 $([IPython.events]).on('notebook_saved.Notebook', function () {
46 46 that.update_notebook_name();
47 47 that.update_document_title();
48 48 });
49 49 $([IPython.events]).on('notebook_renamed.Notebook', function () {
50 that.update_notebook_name();
51 that.update_document_title();
50 that.update_address_bar();
52 51 });
53 52 $([IPython.events]).on('notebook_save_failed.Notebook', function () {
54 53 that.set_save_status('Autosave Failed!');
55 54 });
56 55 $([IPython.events]).on('checkpoints_listed.Notebook', function (event, data) {
57 56 that.set_last_checkpoint(data[0]);
58 57 });
59 58
60 59 $([IPython.events]).on('checkpoint_created.Notebook', function (event, data) {
61 60 that.set_last_checkpoint(data);
62 61 });
63 62 $([IPython.events]).on('set_dirty.Notebook', function (event, data) {
64 63 that.set_autosaved(data.value);
65 64 });
66 65 };
67 66
68 67
69 68 SaveWidget.prototype.rename_notebook = function () {
70 69 var that = this;
71 70 var dialog = $('<div/>').append(
72 71 $("<p/>").addClass("rename-message")
73 72 .html('Enter a new notebook name:')
74 73 ).append(
75 74 $("<br/>")
76 75 ).append(
77 76 $('<input/>').attr('type','text').attr('size','25')
78 77 .val(IPython.notebook.get_notebook_name())
79 78 );
80 79 IPython.dialog.modal({
81 80 title: "Rename Notebook",
82 81 body: dialog,
83 82 buttons : {
84 83 "Cancel": {},
85 84 "OK": {
86 85 class: "btn-primary",
87 86 click: function () {
88 87 var new_name = $(this).find('input').val();
89 88 if (!IPython.notebook.test_notebook_name(new_name)) {
90 89 $(this).find('.rename-message').html(
91 90 "Invalid notebook name. Notebook names must "+
92 91 "have 1 or more characters and can contain any characters " +
93 92 "except :/\\. Please enter a new notebook name:"
94 93 );
95 94 return false;
96 95 } else {
97 96 IPython.notebook.notebook_rename(new_name);
98 97 }
99 98 }}
100 99 },
101 100 open : function (event, ui) {
102 101 var that = $(this);
103 102 // Upon ENTER, click the OK button.
104 103 that.find('input[type="text"]').keydown(function (event, ui) {
105 104 if (event.which === utils.keycodes.ENTER) {
106 105 that.find('.btn-primary').first().click();
107 106 return false;
108 107 }
109 108 });
110 109 that.find('input[type="text"]').focus().select();
111 110 }
112 111 });
113 112 }
114 113
115 114
116 115 SaveWidget.prototype.update_notebook_name = function () {
117 116 var nbname = IPython.notebook.get_notebook_name();
118 117 this.element.find('span#notebook_name').html(nbname);
119 118 };
120 119
121 120
122 121 SaveWidget.prototype.update_document_title = function () {
123 122 var nbname = IPython.notebook.get_notebook_name();
124 123 document.title = nbname;
125 124 };
125
126 SaveWidget.prototype.update_address_bar = function(){
127 var nbname = IPython.notebook.notebook_name;
128 var path = IPython.notebook.notebookPath();
129 window.location = path + nbname;
130 }
126 131
127 132
128 133 SaveWidget.prototype.set_save_status = function (msg) {
129 134 this.element.find('span#autosave_status').html(msg);
130 135 }
131 136
132 137 SaveWidget.prototype.set_checkpoint_status = function (msg) {
133 138 this.element.find('span#checkpoint_status').html(msg);
134 139 }
135 140
136 141 SaveWidget.prototype.set_last_checkpoint = function (checkpoint) {
137 142 if (!checkpoint) {
138 143 this.set_checkpoint_status("");
139 144 return;
140 145 }
141 146 var d = new Date(checkpoint.last_modified);
142 147 this.set_checkpoint_status(
143 148 "Last Checkpoint: " + d.format('mmm dd HH:MM')
144 149 );
145 150 }
146 151
147 152 SaveWidget.prototype.set_autosaved = function (dirty) {
148 153 if (dirty) {
149 154 this.set_save_status("(unsaved changes)");
150 155 } else {
151 156 this.set_save_status("(autosaved)");
152 157 }
153 158 };
154 159
155 160
156 161 IPython.SaveWidget = SaveWidget;
157 162
158 163 return IPython;
159 164
160 165 }(IPython));
161 166
@@ -1,105 +1,105 b''
1 1 """Tornado handlers for the tree 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 from tornado import web
20 20 from ..base.handlers import IPythonHandler
21 21 from urllib import quote, unquote
22 22
23 23 #-----------------------------------------------------------------------------
24 24 # Handlers
25 25 #-----------------------------------------------------------------------------
26 26
27 27
28 28 class ProjectDashboardHandler(IPythonHandler):
29 29
30 30 @web.authenticated
31 31 def get(self):
32 32 self.write(self.render_template('tree.html',
33 33 project=self.project,
34 34 project_component=self.project.split('/'),
35 35 notebook_path= "''"
36 36 ))
37 37
38 38
39 39 class ProjectPathDashboardHandler(IPythonHandler):
40 40
41 41 @authenticate_unless_readonly
42 42 def get(self, notebook_path):
43 43 nbm = self.notebook_manager
44 44 name, path = nbm.named_notebook_path(notebook_path)
45 45 if name != None:
46 46 if path == None:
47 47 self.redirect(self.base_project_url + 'notebooks/' + quote(name))
48 48 else:
49 49 self.redirect(self.base_project_url + 'notebooks/' + path + quote(name))
50 50 else:
51 51 project = self.project + '/' + notebook_path
52 52 self.write(self.render_template('tree.html',
53 53 project=project,
54 54 project_component=project.split('/'),
55 55 notebook_path=path,
56 notebook_name=quote(name)))
56 notebook_name=name))
57 57
58 58
59 59 class TreeRedirectHandler(IPythonHandler):
60 60
61 61 @authenticate_unless_readonly
62 62 def get(self):
63 63 url = self.base_project_url + 'tree'
64 64 self.redirect(url)
65 65
66 66 class TreePathRedirectHandler(IPythonHandler):
67 67
68 68 @authenticate_unless_readonly
69 69 def get(self, notebook_path):
70 70 url = self.base_project_url + 'tree/'+ notebook_path
71 71 self.redirect(url)
72 72
73 73 class ProjectRedirectHandler(IPythonHandler):
74 74
75 75 @authenticate_unless_readonly
76 76 def get(self):
77 77 url = self.base_project_url + 'tree'
78 78 self.redirect(url)
79 79
80 80 class NewFolderHandler(IPythonHandler):
81 81
82 82 @authenticate_unless_readonly
83 83 def get(self, notebook_path):
84 84 nbm = self.notebook_manager
85 85 name, path = nbm.named_notebook_path(notebook_path)
86 86 nbm.add_new_folder(path)
87 87 url = self.base_project_url + 'tree/' + notebook_path
88 88 self.redirect(url)
89 89
90 90
91 91 #-----------------------------------------------------------------------------
92 92 # URL to handler mappings
93 93 #-----------------------------------------------------------------------------
94 94
95 95
96 96 _notebook_path_regex = r"(?P<notebook_path>.+)"
97 97
98 98 default_handlers = [
99 99 (r"/tree/%s/-new" %_notebook_path_regex, NewFolderHandler),
100 100 (r"/tree/%s/" % _notebook_path_regex, TreePathRedirectHandler),
101 101 (r"/tree/%s" % _notebook_path_regex, ProjectPathDashboardHandler),
102 102 (r"/tree", ProjectDashboardHandler),
103 103 (r"/tree/", TreeRedirectHandler),
104 104 (r"/", ProjectRedirectHandler)
105 105 ]
General Comments 0
You need to be logged in to leave comments. Login now