refactor: move form stuff out of source code
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
from owrx.config import Config
|
||||
from owrx.controllers.admin import AuthorizationMixin
|
||||
from owrx.controllers.template import WebpageController
|
||||
from owrx.form.error import FormError
|
||||
from owrx.breadcrumb import Breadcrumb, BreadcrumbItem, BreadcrumbMixin
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from urllib.parse import parse_qs
|
||||
@ -11,45 +10,6 @@ import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Section(object):
|
||||
def __init__(self, title, *inputs):
|
||||
self.title = title
|
||||
self.inputs = inputs
|
||||
|
||||
def render_input(self, input, data, errors):
|
||||
return input.render(data, errors)
|
||||
|
||||
def render_inputs(self, data, errors):
|
||||
return "".join([self.render_input(i, data, errors) for i in self.inputs])
|
||||
|
||||
def classes(self):
|
||||
return ["col-12", "settings-section"]
|
||||
|
||||
def render(self, data, errors):
|
||||
return """
|
||||
<div class="{classes}">
|
||||
<h3 class="settings-header">
|
||||
{title}
|
||||
</h3>
|
||||
{inputs}
|
||||
</div>
|
||||
""".format(
|
||||
classes=" ".join(self.classes()), title=self.title, inputs=self.render_inputs(data, errors)
|
||||
)
|
||||
|
||||
def parse(self, data):
|
||||
parsed_data = {}
|
||||
errors = []
|
||||
for i in self.inputs:
|
||||
try:
|
||||
parsed_data.update(i.parse(data))
|
||||
except FormError as e:
|
||||
errors.append(e)
|
||||
except Exception as e:
|
||||
errors.append(FormError(i.id, "{}: {}".format(type(e).__name__, e)))
|
||||
return parsed_data, errors
|
||||
|
||||
|
||||
class SettingsController(AuthorizationMixin, WebpageController):
|
||||
def indexAction(self):
|
||||
self.serve_template("settings.html", **self.template_variables())
|
||||
|
@ -1,4 +1,5 @@
|
||||
from owrx.controllers.settings import SettingsFormController, Section
|
||||
from owrx.controllers.settings import SettingsFormController
|
||||
from owrx.form.section import Section
|
||||
from owrx.form.input import CheckboxInput, ServicesCheckboxInput
|
||||
from owrx.breadcrumb import Breadcrumb, BreadcrumbItem
|
||||
from owrx.controllers.settings import SettingsBreadcrumb
|
||||
|
@ -1,4 +1,5 @@
|
||||
from owrx.controllers.settings import SettingsFormController, Section, SettingsBreadcrumb
|
||||
from owrx.controllers.settings import SettingsFormController, SettingsBreadcrumb
|
||||
from owrx.form.section import Section
|
||||
from owrx.form.input import CheckboxInput, NumberInput, DropdownInput, Js8ProfileCheckboxInput, MultiCheckboxInput, Option
|
||||
from owrx.form.input.wfm import WfmTauValues
|
||||
from owrx.form.input.wsjt import Q65ModeMatrix, WsjtDecodingDepthsInput
|
||||
|
@ -1,4 +1,5 @@
|
||||
from owrx.controllers.settings import Section, SettingsFormController
|
||||
from owrx.controllers.settings import SettingsFormController
|
||||
from owrx.form.section import Section
|
||||
from owrx.config.core import CoreConfig
|
||||
from owrx.form.input import (
|
||||
TextInput,
|
||||
|
@ -1,4 +1,5 @@
|
||||
from owrx.controllers.settings import SettingsFormController, Section, SettingsBreadcrumb
|
||||
from owrx.controllers.settings import SettingsFormController, SettingsBreadcrumb
|
||||
from owrx.form.section import Section
|
||||
from owrx.form.input.converter import OptionalConverter
|
||||
from owrx.form.input.aprs import AprsBeaconSymbols, AprsAntennaDirections
|
||||
from owrx.form.input import TextInput, CheckboxInput, DropdownInput, NumberInput
|
||||
|
@ -4,7 +4,8 @@ from owrx.controllers.settings import SettingsFormController
|
||||
from owrx.source import SdrDeviceDescription, SdrDeviceDescriptionMissing, SdrClientClass
|
||||
from owrx.config import Config
|
||||
from owrx.connection import OpenWebRxReceiverClient
|
||||
from owrx.controllers.settings import Section, SettingsBreadcrumb
|
||||
from owrx.controllers.settings import SettingsBreadcrumb
|
||||
from owrx.form.section import Section
|
||||
from urllib.parse import quote, unquote
|
||||
from owrx.sdr import SdrService
|
||||
from owrx.form.input import TextInput, DropdownInput, Option
|
||||
|
Reference in New Issue
Block a user