Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support smart redirect based on file extension #54

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions nbclassic/notebook/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
ExtensionHandlerMixin,
ExtensionHandlerJinjaMixin
)
from jupyter_server.base.handlers import path_regex, FilesRedirectHandler
from jupyter_server.base.handlers import path_regex, get_service_name, FilesRedirectHandler
from jupyter_server.utils import (
url_path_join,
url_escape,
Expand Down Expand Up @@ -97,7 +97,11 @@ def get(self, path):
raise
if model['type'] != 'notebook':
# not a notebook, redirect to files
yield FilesRedirectHandler.redirect_to_files(self, path)
url = url_path_join(
self.base_url, get_service_name(model['name']), url_escape(path),
)
self.log.debug("Redirecting %s to %s", self.request.path, url)
self.redirect(url)
name = path.rsplit('/', 1)[-1]
self.write(self.render_template('notebook.html',
notebook_path=path,
Expand Down