From b874583931c6041ae854f798fd20179c62fba9d0 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Sat, 25 Apr 2020 21:42:00 +0200 Subject: [PATCH] setup for multiple settings sections --- htdocs/{admin.html => generalsettings.html} | 0 htdocs/settings.html | 26 +++++++++++++++++++++ owrx/controllers/session.py | 4 ++-- owrx/controllers/settings.py | 11 ++++++--- owrx/controllers/template.py | 2 +- owrx/http.py | 7 +++--- 6 files changed, 41 insertions(+), 9 deletions(-) rename htdocs/{admin.html => generalsettings.html} (100%) create mode 100644 htdocs/settings.html diff --git a/htdocs/admin.html b/htdocs/generalsettings.html similarity index 100% rename from htdocs/admin.html rename to htdocs/generalsettings.html diff --git a/htdocs/settings.html b/htdocs/settings.html new file mode 100644 index 0000000..659b660 --- /dev/null +++ b/htdocs/settings.html @@ -0,0 +1,26 @@ + + + + OpenWebRX Settings + + + + + + + + + +${header} +
+
+

Settings

+
+ + +
+ \ No newline at end of file diff --git a/owrx/controllers/session.py b/owrx/controllers/session.py index dd6d0f9..51bf399 100644 --- a/owrx/controllers/session.py +++ b/owrx/controllers/session.py @@ -46,12 +46,12 @@ class SessionController(WebpageController): if data["user"] in userlist: user = userlist[data["user"]] if user.password.is_valid(data["password"]): - # TODO pass the final destination # TODO evaluate password force_change and redirect to password change key = SessionStorage.getSharedInstance().startSession({"user": user.name}) cookie = SimpleCookie() cookie["owrx-session"] = key - self.send_redirect("/admin", cookies=cookie) + # TODO pass the final destination + self.send_redirect("/settings", cookies=cookie) return self.send_redirect("/login") diff --git a/owrx/controllers/settings.py b/owrx/controllers/settings.py index 8243d09..8f5e11e 100644 --- a/owrx/controllers/settings.py +++ b/owrx/controllers/settings.py @@ -44,6 +44,11 @@ class Section(object): class SettingsController(AdminController): + def indexAction(self): + self.serve_template("settings.html", **self.template_variables()) + + +class GeneralSettingsController(AdminController): sections = [ Section( "General settings", @@ -222,7 +227,7 @@ class SettingsController(AdminController): ] def render_sections(self): - sections = "".join(section.render() for section in SettingsController.sections) + sections = "".join(section.render() for section in GeneralSettingsController.sections) return """
{sections} @@ -235,7 +240,7 @@ class SettingsController(AdminController): ) def indexAction(self): - self.serve_template("admin.html", **self.template_variables()) + self.serve_template("generalsettings.html", **self.template_variables()) def template_variables(self): variables = super().template_variables() @@ -245,7 +250,7 @@ class SettingsController(AdminController): def processFormData(self): data = parse_qs(self.get_body().decode("utf-8")) data = { - k: v for i in SettingsController.sections for k, v in i.parse(data).items() + k: v for i in GeneralSettingsController.sections for k, v in i.parse(data).items() } config = Config.get() for k, v in data.items(): diff --git a/owrx/controllers/template.py b/owrx/controllers/template.py index 4adbe8c..6030fd1 100644 --- a/owrx/controllers/template.py +++ b/owrx/controllers/template.py @@ -23,7 +23,7 @@ class WebpageController(TemplateController): settingslink = "" pm = Config.get() if "webadmin_enabled" in pm and pm["webadmin_enabled"]: - settingslink = """
Settings
""" + settingslink = """
Settings
""" header = self.render_template("include/header.include.html", settingslink=settingslink) return {"header": header} diff --git a/owrx/http.py b/owrx/http.py index 7e8d104..b8ec63c 100644 --- a/owrx/http.py +++ b/owrx/http.py @@ -11,7 +11,7 @@ from owrx.controllers.assets import ( from owrx.controllers.websocket import WebSocketController from owrx.controllers.api import ApiController from owrx.controllers.metrics import MetricsController -from owrx.controllers.settings import SettingsController +from owrx.controllers.settings import SettingsController, GeneralSettingsController from owrx.controllers.session import SessionController from http.server import BaseHTTPRequestHandler from urllib.parse import urlparse, parse_qs @@ -100,8 +100,9 @@ class Router(object): StaticRoute("/features", FeatureController), StaticRoute("/api/features", ApiController), StaticRoute("/metrics", MetricsController), - StaticRoute("/admin", SettingsController), - StaticRoute("/admin", SettingsController, method="POST", options={"action": "processFormData"}), + StaticRoute("/settings", SettingsController), + StaticRoute("/generalsettings", GeneralSettingsController), + StaticRoute("/generalsettings", GeneralSettingsController, method="POST", options={"action": "processFormData"}), StaticRoute("/login", SessionController, options={"action": "loginAction"}), StaticRoute("/login", SessionController, method="POST", options={"action": "processLoginAction"}), StaticRoute("/logout", SessionController, options={"action": "logoutAction"}),