From 8304018688b7d39091a85802fe7cbbe521bb7c4e Mon Sep 17 00:00:00 2001 From: Mario Buikhuizen Date: Fri, 13 Dec 2019 19:09:31 +0100 Subject: [PATCH 1/2] fix: the default title in the template is always Notebook The property used as a fallback for the title of the template is not initialized by Voila. Following nbconvert, in which this property is set to the filename of the notebook [1], this commit now does the same. Related to: voila-dashboards/voila-vuetify#25 [1] https://github.com/jupyter/nbconvert/blob/6c6e5fa0c757169017fd325fad98efa8d4a368ea/nbconvert/exporters/exporter.py#L172 --- voila/handler.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/voila/handler.py b/voila/handler.py index 30e58f4a9..ecf50f3e3 100644 --- a/voila/handler.py +++ b/voila/handler.py @@ -59,11 +59,17 @@ async def get(self, path=None): return self.cwd = os.path.dirname(notebook_path) + path, basename = os.path.split(notebook_path) + notebook_name = os.path.splitext(basename)[0] + # render notebook to html resources = { 'base_url': self.base_url, 'nbextensions': nbextensions, - 'theme': self.voila_configuration.theme + 'theme': self.voila_configuration.theme, + 'metadata': { + 'name': notebook_name + } } # include potential extra resources From 3cefe672b42e445c8c0ac996fc560fa8a9eb3fd1 Mon Sep 17 00:00:00 2001 From: "Maarten A. Breddels" Date: Wed, 18 Dec 2019 10:41:47 +0100 Subject: [PATCH 2/2] test: source code was detected because the title matched --- tests/app/execute_test.py | 2 +- tests/server/execute_test.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/app/execute_test.py b/tests/app/execute_test.py index bf34b0234..3aecb2c6d 100644 --- a/tests/app/execute_test.py +++ b/tests/app/execute_test.py @@ -19,7 +19,7 @@ def test_hello_world(http_client, base_url): assert response.code == 200 html_text = response.body.decode('utf-8') assert 'Hi Voila' in html_text - assert 'print' not in html_text, 'by default the source code should be stripped' + assert 'print(' not in html_text, 'by default the source code should be stripped' assert 'test_template.css' not in html_text, "test_template should not be the default" diff --git a/tests/server/execute_test.py b/tests/server/execute_test.py index 801c35e6c..692151a1f 100644 --- a/tests/server/execute_test.py +++ b/tests/server/execute_test.py @@ -8,5 +8,5 @@ def test_hello_world(http_client, print_notebook_url): assert response.code == 200 html_text = response.body.decode('utf-8') assert 'Hi Voila' in html_text - assert 'print' not in html_text, 'by default the source code should be stripped' + assert 'print(' not in html_text, 'by default the source code should be stripped' assert 'test_template.css' not in html_text, "test_template should not be the default"