Skip to content

Commit

Permalink
Update tree handler
Browse files Browse the repository at this point in the history
  • Loading branch information
trungleduc committed Mar 21, 2023
1 parent 1286f00 commit 6068e64
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
3 changes: 1 addition & 2 deletions voila/server_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from .utils import get_server_root_dir


def _jupyter_server_extension_paths():
def _jupyter_server_extension_points():
"""
Returns a list of dictionaries with metadata describing
where to find the `_load_jupyter_server_extension` function.
Expand All @@ -38,7 +38,6 @@ def _jupyter_server_extension_paths():

def _load_jupyter_server_extension(server_app):
web_app = server_app.web_app

# common configuration options between the server extension and the application
voila_configuration = VoilaConfiguration(parent=server_app)
template_name = voila_configuration.template
Expand Down
17 changes: 10 additions & 7 deletions voila/treehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from .handler import BaseVoilaHandler
from .utils import get_server_root_dir
from nbclient.util import ensure_async


class VoilaTreeHandler(BaseVoilaHandler):
Expand Down Expand Up @@ -51,16 +52,18 @@ def generate_page_title(self, path):
return "Voilà Home"

@web.authenticated
def get(self, path=""):
async def get(self, path=""):
cm = self.contents_manager

if cm.dir_exists(path=path):
if cm.is_hidden(path) and not cm.allow_hidden:
dir_exists = await ensure_async(cm.dir_exists(path=path))
file_exists = await ensure_async(cm.file_exists(path))
if dir_exists:
is_hidden = await ensure_async(cm.is_hidden(path))
if is_hidden and not cm.allow_hidden:
self.log.info("Refusing to serve hidden directory, via 404 Error")
raise web.HTTPError(404)
breadcrumbs = self.generate_breadcrumbs(path)
page_title = self.generate_page_title(path)
contents = cm.get(path)
contents = await ensure_async(cm.get(path))

def allowed_content(content):
if content["type"] in ["directory", "notebook"]:
Expand All @@ -85,9 +88,9 @@ def allowed_content(content):
query=self.request.query,
)
)
elif cm.file_exists(path):
elif file_exists:
# it's not a directory, we have redirecting to do
model = cm.get(path, content=False)
model = await ensure_async(cm.get(path, content=False))
# redirect to /api/notebooks if it's a notebook, otherwise /api/files
service = "notebooks" if model["type"] == "notebook" else "files"
url = url_path_join(
Expand Down

0 comments on commit 6068e64

Please sign in to comment.