Replace pages' use of the options call with directly building the HTML components using templates, as the syntax is much nicer. Use a common set of data provided to all modules via pagetemplate.py instead of passing things like web_ui_options around. Closes #153

This commit is contained in:
Ian Renton
2026-09-25 21:22:31 +01:00
parent 4df00c321c
commit 8de163469b
27 changed files with 493 additions and 534 deletions
+26 -8
View File
@@ -1,3 +1,4 @@
import re
from typing import Any
import tornado
@@ -5,7 +6,6 @@ from tornado import httputil
from tornado.web import Application
from core.config import (
ALLOW_SPOTTING,
BASE_URL,
SERVER_OWNER_CALLSIGN,
TELNET_SERVER_ADDRESS,
@@ -14,6 +14,14 @@ from core.config import (
WEB_UI_OPTIONS,
)
from core.constants import SOFTWARE_VERSION
from core.utils import infer_mode_type_from_mode, safe_json_dumps
from webserver.handlers.api.options import build_options
def dom_safe_name(name):
"""Strip characters from a name that are not allowed in HTML element IDs"""
return re.sub(r"^[^A-Za-z0-9]+|\W+", "", name, flags=re.ASCII)
class PageTemplateHandler(tornado.web.RequestHandler):
@@ -31,17 +39,27 @@ class PageTemplateHandler(tornado.web.RequestHandler):
def initialize(self, template_name):
self._template_name = template_name
def get(self):
# Load named template, and provide variables used in templates
self.render(
f"{self._template_name}.html",
def get_template_namespace(self):
"""Provide variables and helper functions to all page templates"""
namespace = super().get_template_namespace()
namespace.update(
# Various options
options=build_options(),
web_ui_options=WEB_UI_OPTIONS,
# Other single static parameters
software_version=SOFTWARE_VERSION,
server_owner_callsign=SERVER_OWNER_CALLSIGN,
allow_spotting=ALLOW_SPOTTING,
web_ui_options=WEB_UI_OPTIONS,
baseurl=BASE_URL,
telnet_server_enabled=TELNET_SERVER_ENABLED,
telnet_server_address=TELNET_SERVER_ADDRESS,
telnet_server_port=TELNET_SERVER_PORT,
current_path=self.request.path,
# Function references that templates need
dom_safe_name=dom_safe_name,
safe_json_dumps=safe_json_dumps,
infer_mode_type_from_mode=infer_mode_type_from_mode,
)
return namespace
def get(self):
self.render(f"{self._template_name}.html")