Skip to content

Commit 04169e2

Browse files
authored
Allow NBClassic to work with NB7 and ServerApp.base_url (#165)
* Allow NBClassic to work if ServerApp.base_url is set and Notebook 7 is installed Also resolves an issue where New->New Notebook did not respect the "/nbclassic/" in the url if it was set Personally not a fan of the var still being called base_url_prefix but wans't willing to make that big of a change Closes #164 * Change name of url prefix to be more appropriate Rename base_url_prefix to nbclassic_path rename baseUrlPrefix to nbclassicPath rename url_prefix_notebook() to nbclassic_path()
1 parent 26e49b4 commit 04169e2

File tree

22 files changed

+43
-41
lines changed

22 files changed

+43
-41
lines changed

nbclassic/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
]
5656

5757

58-
def url_prefix_notebook():
58+
def nbclassic_path():
5959
if NOTEBOOK_V7_DETECTED:
6060
return "/nbclassic"
6161
return ""

nbclassic/bundler/handlers.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import inspect
88
import concurrent.futures
99

10-
from nbclassic import url_prefix_notebook
10+
from nbclassic import nbclassic_path
1111

1212
from traitlets.utils.importstring import import_item
1313
from tornado import web, gen
@@ -16,8 +16,6 @@
1616
from jupyter_server.base.handlers import JupyterHandler
1717
from jupyter_server.services.config import ConfigManager
1818

19-
from nbclassic import url_prefix_notebook
20-
2119
from . import tools
2220

2321

@@ -108,5 +106,5 @@ def get(self, path):
108106

109107

110108
default_handlers = [
111-
(r"%s/bundle/(.*)" % url_prefix_notebook(), BundlerHandler)
109+
(r"%s/bundle/(.*)" % nbclassic_path(), BundlerHandler)
112110
]

nbclassic/edit/handlers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
ExtensionHandlerJinjaMixin
1414
)
1515

16-
from nbclassic import url_prefix_notebook
16+
from nbclassic import nbclassic_path
1717

1818

1919
class EditorHandler(ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, JupyterHandler):
@@ -35,5 +35,5 @@ def get(self, path):
3535

3636

3737
default_handlers = [
38-
(r"{}/edit{}".format(url_prefix_notebook(), path_regex), EditorHandler),
38+
(r"{}/edit{}".format(nbclassic_path(), path_regex), EditorHandler),
3939
]

nbclassic/notebook/handlers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from jupyter_server.base.handlers import JupyterHandler
2323
HTTPError = web.HTTPError
2424

25-
from nbclassic import url_prefix_notebook
25+
from nbclassic import nbclassic_path
2626

2727

2828
def get_frontend_exporters():
@@ -114,5 +114,5 @@ def get(self, path):
114114

115115

116116
default_handlers = [
117-
(r"{}/notebooks{}".format(url_prefix_notebook(), path_regex), NotebookHandler),
117+
(r"{}/notebooks{}".format(nbclassic_path(), path_regex), NotebookHandler),
118118
]

nbclassic/notebookapp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from nbclassic import (
1717
DEFAULT_STATIC_FILES_PATH,
1818
DEFAULT_TEMPLATE_PATH_LIST,
19-
url_prefix_notebook
19+
nbclassic_path
2020
)
2121

2222
from nbclassic._version import __version__
@@ -118,7 +118,7 @@ class NotebookApp(
118118
extension_url = "/tree"
119119
subcommands = {}
120120

121-
default_url = Unicode("%s/tree" % url_prefix_notebook()).tag(config=True)
121+
default_url = Unicode("%s/tree" % nbclassic_path()).tag(config=True)
122122

123123
# Override the default open_Browser trait in ExtensionApp,
124124
# setting it to True.
@@ -194,7 +194,7 @@ def _prepare_templates(self):
194194
nbui = gettext.translation('nbui', localedir=os.path.join(
195195
base_dir, 'nbclassic/i18n'), fallback=True)
196196
self.jinja2_env.install_gettext_translations(nbui, newstyle=False)
197-
self.jinja2_env.globals.update(base_url_prefix=url_prefix_notebook)
197+
self.jinja2_env.globals.update(nbclassic_path=nbclassic_path)
198198

199199
def _link_jupyter_server_extension(self, serverapp):
200200
# Monkey-patch Jupyter Server's and nbclassic's static path list to include

nbclassic/static/edit/js/menubar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ define([
2828
* file_path : string
2929
*/
3030
options = options || {};
31-
this.base_url_prefix = options.base_url_prefix;
31+
this.nbclassic_path = options.nbclassic_path;
3232
this.base_url = options.base_url || utils.get_body_data("baseUrl");
3333
this.selector = selector;
3434
this.editor = options.editor;
@@ -55,7 +55,7 @@ define([
5555
editor.contents.new_untitled(parent, {type: "file"}).then(
5656
function (data) {
5757
w.location = utils.url_path_join(
58-
that.base_url_prefix, that.base_url, 'edit', utils.encode_uri_components(data.path)
58+
that.base_url, that.nbclassic_path, 'edit', utils.encode_uri_components(data.path)
5959
);
6060
},
6161
function(error) {

nbclassic/static/notebook/js/about.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ requirejs([
99
], function ($, dialog, i18n, _, IPython) {
1010
'use strict';
1111
$('#notebook_about').click(function () {
12-
// The baseUrlPrefix is only injected in the document by nbclassic.
13-
var is_nbclassic = document.baseUrlPrefix !== undefined;
12+
// The nbclassicPath is only injected in the document by nbclassic.
13+
var is_nbclassic = document.nbclassicPath !== undefined;
1414
// use underscore template to auto html escape
1515
if (sys_info) {
1616
var text = '';

nbclassic/static/notebook/js/kernelselector.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ define([
1010
], function($, IPython, dialog, utils, i18n) {
1111
"use strict";
1212

13-
var KernelSelector = function(selector, notebook) {
13+
var KernelSelector = function(selector, notebook, options) {
14+
options = options || {};
1415
var that = this;
1516
this.selector = selector;
1617
this.notebook = notebook;
18+
this.nbclassic_path = options.nbclassic_path;
1719
this.notebook.set_kernelselector(this);
1820
this.events = notebook.events;
1921
this.current_selection = null;
@@ -307,7 +309,7 @@ define([
307309
that.notebook.contents.new_untitled(parent, {type: "notebook"}).then(
308310
function (data) {
309311
var url = utils.url_path_join(
310-
that.notebook.base_url, 'notebooks',
312+
that.notebook.base_url, that.nbclassic_path, 'notebooks',
311313
utils.encode_uri_components(data.path)
312314
);
313315
url += "?kernel_name=" + kernel_name;

nbclassic/static/notebook/js/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ requirejs([
104104
var common_options = {
105105
ws_url : utils.get_body_data("wsUrl"),
106106
base_url : utils.get_body_data("baseUrl"),
107+
nbclassic_path: document.nbclassicPath || "",
107108
notebook_path : utils.get_body_data("notebookPath"),
108109
notebook_name : utils.get_body_data('notebookName')
109110
};
@@ -168,7 +169,7 @@ requirejs([
168169
keyboard_manager: keyboard_manager});
169170
notification_area.init_notification_widgets();
170171
var kernel_selector = new kernelselector.KernelSelector(
171-
'#kernel_logo_widget', notebook);
172+
'#kernel_logo_widget', notebook, common_options);
172173
searchandreplace.load(keyboard_manager);
173174

174175
$('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+

nbclassic/static/notebook/js/menubar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ define([
3636
* config: ConfigSection instance
3737
*/
3838
options = options || {};
39-
this.base_url_prefix = options.base_url_prefix;
39+
this.nbclassic_path = options.nbclassic_path;
4040
this.base_url = options.base_url || utils.get_body_data("baseUrl");
4141
this.selector = selector;
4242
this.notebook = options.notebook;
@@ -178,7 +178,7 @@ define([
178178
var parent = utils.url_path_split(that.notebook.notebook_path)[0];
179179
window.open(
180180
utils.url_path_join(
181-
that.base_url_prefix, that.base_url, 'tree',
181+
that.base_url, that.nbclassic_path, 'tree',
182182
utils.encode_uri_components(parent)
183183
), IPython._target);
184184
});

0 commit comments

Comments
 (0)