From 391069653ab0f160e8f447227c531e5a9c604e19 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Mon, 15 Feb 2021 15:29:02 +0100 Subject: [PATCH] split settings controller module (preparation to split general settings) --- owrx/controllers/settings/__init__.py | 33 ++++++++ .../{settings.py => settings/general.py} | 75 +------------------ owrx/controllers/settings/sdr.py | 44 +++++++++++ owrx/http.py | 4 +- setup.py | 1 + 5 files changed, 84 insertions(+), 73 deletions(-) create mode 100644 owrx/controllers/settings/__init__.py rename owrx/controllers/{settings.py => settings/general.py} (86%) create mode 100644 owrx/controllers/settings/sdr.py diff --git a/owrx/controllers/settings/__init__.py b/owrx/controllers/settings/__init__.py new file mode 100644 index 0000000..0970b3d --- /dev/null +++ b/owrx/controllers/settings/__init__.py @@ -0,0 +1,33 @@ +from owrx.config import Config +from owrx.controllers.admin import AuthorizationMixin +from owrx.controllers.template import WebpageController + + +class Section(object): + def __init__(self, title, *inputs): + self.title = title + self.inputs = inputs + + def render_inputs(self): + config = Config.get() + return "".join([i.render(config) for i in self.inputs]) + + def render(self): + return """ +
+

+ {title} +

+ {inputs} +
+ """.format( + title=self.title, inputs=self.render_inputs() + ) + + def parse(self, data): + return {k: v for i in self.inputs for k, v in i.parse(data).items()} + + +class SettingsController(AuthorizationMixin, WebpageController): + def indexAction(self): + self.serve_template("settings.html", **self.template_variables()) diff --git a/owrx/controllers/settings.py b/owrx/controllers/settings/general.py similarity index 86% rename from owrx/controllers/settings.py rename to owrx/controllers/settings/general.py index dd1281b..c19a16a 100644 --- a/owrx/controllers/settings.py +++ b/owrx/controllers/settings/general.py @@ -1,3 +1,4 @@ +from owrx.controllers.settings import Section from owrx.controllers.template import WebpageController from owrx.controllers.admin import AuthorizationMixin from owrx.config.core import CoreConfig @@ -22,86 +23,16 @@ from owrx.form.aprs import AprsBeaconSymbols, AprsAntennaDirections from owrx.form.wfm import WfmTauValues from owrx.form.wsjt import Q65ModeMatrix from owrx.form.gfx import AvatarInput, TopPhotoInput -from urllib.parse import quote from owrx.wsjt import Fst4Profile, Fst4wProfile -import json -import logging import shutil import os from glob import glob +import logging + logger = logging.getLogger(__name__) -class Section(object): - def __init__(self, title, *inputs): - self.title = title - self.inputs = inputs - - def render_inputs(self): - config = Config.get() - return "".join([i.render(config) for i in self.inputs]) - - def render(self): - return """ -
-

- {title} -

- {inputs} -
- """.format( - title=self.title, inputs=self.render_inputs() - ) - - def parse(self, data): - return {k: v for i in self.inputs for k, v in i.parse(data).items()} - - -class SettingsController(AuthorizationMixin, WebpageController): - def indexAction(self): - self.serve_template("settings.html", **self.template_variables()) - - -class SdrSettingsController(AuthorizationMixin, WebpageController): - def header_variables(self): - variables = super().header_variables() - variables["assets_prefix"] = "../" - return variables - - def template_variables(self): - variables = super().template_variables() - variables["devices"] = self.render_devices() - return variables - - def render_devices(self): - return "".join(self.render_device(key, value) for key, value in Config.get()["sdrs"].items()) - - def render_device(self, device_id, config): - return """ -
-
- {device_name} -
-
- {form} -
-
- """.format( - device_name=config["name"], form=self.render_form(device_id, config) - ) - - def render_form(self, device_id, config): - return """ -
- """.format( - device_id=device_id, formdata=quote(json.dumps(config)) - ) - - def indexAction(self): - self.serve_template("settings/sdr.html", **self.template_variables()) - - class GeneralSettingsController(AuthorizationMixin, WebpageController): sections = [ Section( diff --git a/owrx/controllers/settings/sdr.py b/owrx/controllers/settings/sdr.py new file mode 100644 index 0000000..ec5b601 --- /dev/null +++ b/owrx/controllers/settings/sdr.py @@ -0,0 +1,44 @@ +from owrx.controllers.admin import AuthorizationMixin +from owrx.controllers.template import WebpageController +from owrx.config import Config +from urllib.parse import quote +import json + + +class SdrSettingsController(AuthorizationMixin, WebpageController): + def header_variables(self): + variables = super().header_variables() + variables["assets_prefix"] = "../" + return variables + + def template_variables(self): + variables = super().template_variables() + variables["devices"] = self.render_devices() + return variables + + def render_devices(self): + return "".join(self.render_device(key, value) for key, value in Config.get()["sdrs"].items()) + + def render_device(self, device_id, config): + return """ +
+
+ {device_name} +
+
+ {form} +
+
+ """.format( + device_name=config["name"], form=self.render_form(device_id, config) + ) + + def render_form(self, device_id, config): + return """ +
+ """.format( + device_id=device_id, formdata=quote(json.dumps(config)) + ) + + def indexAction(self): + self.serve_template("settings/sdr.html", **self.template_variables()) diff --git a/owrx/http.py b/owrx/http.py index 90d4a72..1ef8339 100644 --- a/owrx/http.py +++ b/owrx/http.py @@ -4,7 +4,9 @@ from owrx.controllers.assets import OwrxAssetsController, AprsSymbolsController, from owrx.controllers.websocket import WebSocketController from owrx.controllers.api import ApiController from owrx.controllers.metrics import MetricsController -from owrx.controllers.settings import SettingsController, GeneralSettingsController, SdrSettingsController +from owrx.controllers.settings import SettingsController +from owrx.controllers.settings.general import GeneralSettingsController +from owrx.controllers.settings.sdr import SdrSettingsController from owrx.controllers.bookmarks import BookmarksController from owrx.controllers.session import SessionController from owrx.controllers.profile import ProfileController diff --git a/setup.py b/setup.py index f15522a..bcafa1b 100644 --- a/setup.py +++ b/setup.py @@ -18,6 +18,7 @@ setup( "owrx.source", "owrx.service", "owrx.controllers", + "owrx.controllers.settings", "owrx.property", "owrx.form", "owrx.config",