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

Add a redirect handler to open non-notebook files from the cli #45

Merged
merged 4 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions nbclassic/notebookapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import gettext

from jinja2 import Environment, FileSystemLoader
from tornado.web import RedirectHandler

import notebook
from notebook import (
Expand Down Expand Up @@ -126,6 +127,7 @@ class NotebookApp(
aliases = aliases
flags = flags
extension_url = "/tree"
subcommands = {}
Zsailer marked this conversation as resolved.
Show resolved Hide resolved

# Override the default open_Browser trait in ExtensionApp,
# setting it to True.
Expand Down Expand Up @@ -218,6 +220,17 @@ def initialize_handlers(self):
"""Load the (URL pattern, handler) tuples for each component."""
# Order matters. The first handler to match the URL will handle the request.
handlers = []

# Add a redirect from /notebooks to /edit
# for opening non-ipynb files in edit mode.
handlers.append(
(
rf"/{self.file_url_prefix}/((?!.*\.ipynb($|\?)).*)",
RedirectHandler,
{"url": "/edit/{0}"}
)
)

# load extra services specified by users before default handlers
for service in self.settings['extra_services']:
handlers.extend(load_handlers(service))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
python_requires='>=3.6',
include_package_data=True,
install_requires = [
'jupyter_server~=1.1',
'jupyter_server~=1.4',
Zsailer marked this conversation as resolved.
Show resolved Hide resolved
'notebook<7',
],
entry_points = {
Expand Down