from typing import Any import tornado from tornado import httputil from tornado.web import Application from core.config import ( ALLOW_SPOTTING, BASE_URL, SERVER_OWNER_CALLSIGN, TELNET_SERVER_ADDRESS, TELNET_SERVER_ENABLED, TELNET_SERVER_PORT, WEB_UI_OPTIONS, ) from core.constants import SOFTWARE_VERSION class PageTemplateHandler(tornado.web.RequestHandler): """Handler for all HTML pages generated from templates""" def __init__( self, application: "Application", request: httputil.HTTPServerRequest, **kwargs: Any, ): self._template_name = None super().__init__(application, request, **kwargs) 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", 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, )