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 tree redirection for edit endpoint. #60

Open
wants to merge 2 commits 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
28 changes: 17 additions & 11 deletions nbclassic/edit/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

from tornado import web
from tornado import web, gen
from jupyter_server.base.handlers import JupyterHandler, path_regex
from jupyter_server.utils import url_escape
from jupyter_server.utils import url_path_join, url_escape, ensure_async
from jupyter_server.extension.handler import (
ExtensionHandlerMixin,
ExtensionHandlerJinjaMixin
Expand All @@ -16,18 +16,24 @@ class EditorHandler(ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, JupyterHa
"""Render the text editor interface."""

@web.authenticated
@gen.coroutine
def get(self, path):
path = path.strip('/')
if not self.contents_manager.file_exists(path):
raise web.HTTPError(404, u'File does not exist: %s' % path)
if (self.contents_manager.dir_exists(path)):
# it's a *directory*, redirect to /tree
url = url_path_join(self.base_url, 'tree', url_escape(path))
self.redirect(url)
else:
path = path.strip('/')
if not (self.contents_manager.file_exists(path)):
raise web.HTTPError(404, u'File does not exist: %s' % path)

basename = path.rsplit('/', 1)[-1]
self.write(self.render_template('edit.html',
file_path=url_escape(path),
basename=basename,
page_title=basename + " (editing)",
basename = path.rsplit('/', 1)[-1]
self.write(self.render_template('edit.html',
file_path=url_escape(path),
basename=basename,
page_title=basename + " (editing)",
)
)
)

default_handlers = [
(r"/edit%s" % path_regex, EditorHandler),
Expand Down