ソースを参照

Add a stub for settings handling

Steven Silvester 7 年 前
コミット
9650e0f2fd
2 ファイル変更45 行追加0 行削除
  1. 11 0
      jupyterlab/extension.py
  2. 34 0
      jupyterlab/settings_handler.py

+ 11 - 0
jupyterlab/extension.py

@@ -8,6 +8,7 @@ import os
 from jupyterlab_launcher import add_handlers, LabConfig
 
 from .commands import get_app_dir, list_extensions, should_build
+from .settings_handler import setting_path, SettingsHandler
 from ._version import __version__
 
 #-----------------------------------------------------------------------------
@@ -89,3 +90,13 @@ def load_jupyter_server_extension(nbapp):
         nbapp.log.info(CORE_NOTE.strip())
 
     add_handlers(web_app, config)
+
+    # TODO: how do we handle this for dev_mode?
+    # TODO: how to we handle core extensions in app_mode?
+    schemas_path = ''
+    settings_path = ''
+    settings_handler = (setting_path, SettingsHandler, {
+        schemas_path: schemas_path,
+        settings_path: settings_path
+    })
+    web_app.add_handlers(".*$", [settings_handler])

+ 34 - 0
jupyterlab/settings_handler.py

@@ -0,0 +1,34 @@
+"""Tornado handlers for frontend config storage."""
+
+# Copyright (c) Jupyter Development Team.
+# Distributed under the terms of the Modified BSD License.
+import json
+from tornado import web
+
+from ...base.handlers import APIHandler, json_errors
+
+
+class SettingsHandler(APIHandler):
+
+    def initialize(self, schemas_path, settings_path):
+        self.schemas_path = schemas_path
+        self.settings_path = settings_path
+
+    @json_errors
+    @web.authenticated
+    def get(self, section_name):
+        self.set_header("Content-Type", 'application/json')
+        # TODO: get the appropriate schema and settings for the section name.
+        self.finish(json.dumps(dict()))
+
+    @json_errors
+    @web.authenticated
+    def put(self, section_name):
+        data = self.get_json_body()  # Will raise 400 if content is not valid JSON
+        print(section_name, data)
+        # TODO: set the appropriate settings for the section name.
+        self.set_status(204)
+
+
+# The path for a labsettings section.
+settings_path = r"/labsettings/(?P<section_name>\w+)"