split settings controller module (preparation to split general settings)

This commit is contained in:
Jakob Ketterl 2021-02-15 15:29:02 +01:00
parent 830d7ae656
commit 391069653a
5 changed files with 84 additions and 73 deletions

View File

@ -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 """
<div class="col-12 settings-section">
<h3 class="settings-header">
{title}
</h3>
{inputs}
</div>
""".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())

View File

@ -1,3 +1,4 @@
from owrx.controllers.settings import Section
from owrx.controllers.template import WebpageController from owrx.controllers.template import WebpageController
from owrx.controllers.admin import AuthorizationMixin from owrx.controllers.admin import AuthorizationMixin
from owrx.config.core import CoreConfig 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.wfm import WfmTauValues
from owrx.form.wsjt import Q65ModeMatrix from owrx.form.wsjt import Q65ModeMatrix
from owrx.form.gfx import AvatarInput, TopPhotoInput from owrx.form.gfx import AvatarInput, TopPhotoInput
from urllib.parse import quote
from owrx.wsjt import Fst4Profile, Fst4wProfile from owrx.wsjt import Fst4Profile, Fst4wProfile
import json
import logging
import shutil import shutil
import os import os
from glob import glob from glob import glob
import logging
logger = logging.getLogger(__name__) 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 """
<div class="col-12 settings-section">
<h3 class="settings-header">
{title}
</h3>
{inputs}
</div>
""".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 """
<div class="card device bg-dark text-white">
<div class="card-header">
{device_name}
</div>
<div class="card-body">
{form}
</div>
</div>
""".format(
device_name=config["name"], form=self.render_form(device_id, config)
)
def render_form(self, device_id, config):
return """
<form class="sdrdevice" data-config="{formdata}"></form>
""".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): class GeneralSettingsController(AuthorizationMixin, WebpageController):
sections = [ sections = [
Section( Section(

View File

@ -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 """
<div class="card device bg-dark text-white">
<div class="card-header">
{device_name}
</div>
<div class="card-body">
{form}
</div>
</div>
""".format(
device_name=config["name"], form=self.render_form(device_id, config)
)
def render_form(self, device_id, config):
return """
<form class="sdrdevice" data-config="{formdata}"></form>
""".format(
device_id=device_id, formdata=quote(json.dumps(config))
)
def indexAction(self):
self.serve_template("settings/sdr.html", **self.template_variables())

View File

@ -4,7 +4,9 @@ from owrx.controllers.assets import OwrxAssetsController, AprsSymbolsController,
from owrx.controllers.websocket import WebSocketController from owrx.controllers.websocket import WebSocketController
from owrx.controllers.api import ApiController from owrx.controllers.api import ApiController
from owrx.controllers.metrics import MetricsController 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.bookmarks import BookmarksController
from owrx.controllers.session import SessionController from owrx.controllers.session import SessionController
from owrx.controllers.profile import ProfileController from owrx.controllers.profile import ProfileController

View File

@ -18,6 +18,7 @@ setup(
"owrx.source", "owrx.source",
"owrx.service", "owrx.service",
"owrx.controllers", "owrx.controllers",
"owrx.controllers.settings",
"owrx.property", "owrx.property",
"owrx.form", "owrx.form",
"owrx.config", "owrx.config",