From df4509066da2a6e913534b2eebc3bbcb63bc7084 Mon Sep 17 00:00:00 2001 From: Philipp Otto Date: Wed, 2 Nov 2022 07:52:02 +0100 Subject: [PATCH 1/2] try to fix wk lib snippet generation --- .../oxalis/view/action-bar/python_client_modal_view.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/frontend/javascripts/oxalis/view/action-bar/python_client_modal_view.tsx b/frontend/javascripts/oxalis/view/action-bar/python_client_modal_view.tsx index a32f5228315..abec038e4db 100644 --- a/frontend/javascripts/oxalis/view/action-bar/python_client_modal_view.tsx +++ b/frontend/javascripts/oxalis/view/action-bar/python_client_modal_view.tsx @@ -43,21 +43,24 @@ function _PythonClientModalView(props: Props): JSX.Element { "loading...", [activeUser], ); + const wkInitSnippet = `import webknossos as wk -with wk.webknossos_context(token="${authToken || ""}"): +with wk.webknossos_context(token="${authToken || ""}", url="${ + window.location.origin + }"): # Download the dataset. dataset = wk.Dataset.download( - webknossos_url="${window.location.origin}", dataset_name_or_url="${dataset.name}", organization_id="${dataset.owningOrganization}", + webknossos_url="${window.location.origin}", ) # Alternatively, directly open the dataset. Image data will be # streamed when being accessed. remote_dataset = wk.Dataset.open_remote( - webknossos_url="${window.location.origin}", dataset_name_or_url="${dataset.name}", organization_id="${dataset.owningOrganization}", + webknossos_url="${window.location.origin}", ) `; From 733518d72b420b1d70f4c2cfbf1430016f919ef1 Mon Sep 17 00:00:00 2001 From: Philipp Otto Date: Tue, 8 Nov 2022 18:59:47 +0100 Subject: [PATCH 2/2] dont output wk url in python snippet when host is webknossos.org --- .../action-bar/python_client_modal_view.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/frontend/javascripts/oxalis/view/action-bar/python_client_modal_view.tsx b/frontend/javascripts/oxalis/view/action-bar/python_client_modal_view.tsx index abec038e4db..c53c490b45a 100644 --- a/frontend/javascripts/oxalis/view/action-bar/python_client_modal_view.tsx +++ b/frontend/javascripts/oxalis/view/action-bar/python_client_modal_view.tsx @@ -44,23 +44,26 @@ function _PythonClientModalView(props: Props): JSX.Element { [activeUser], ); + const nonDefaultHost = !document.location.host.endsWith("webknossos.org"); + const indention = "\n "; + const contextUrlAddendum = nonDefaultHost ? `, url="${window.location.origin}"` : ""; + const maybeUrlParameter = nonDefaultHost + ? `${indention}webknossos_url="${window.location.origin}"` + : ""; + const wkInitSnippet = `import webknossos as wk -with wk.webknossos_context(token="${authToken || ""}", url="${ - window.location.origin - }"): +with wk.webknossos_context(token="${authToken || ""}"${contextUrlAddendum}): # Download the dataset. dataset = wk.Dataset.download( dataset_name_or_url="${dataset.name}", - organization_id="${dataset.owningOrganization}", - webknossos_url="${window.location.origin}", + organization_id="${dataset.owningOrganization}",${maybeUrlParameter} ) # Alternatively, directly open the dataset. Image data will be # streamed when being accessed. remote_dataset = wk.Dataset.open_remote( dataset_name_or_url="${dataset.name}", - organization_id="${dataset.owningOrganization}", - webknossos_url="${window.location.origin}", + organization_id="${dataset.owningOrganization}",${maybeUrlParameter} ) `;