resolve the ugly assets_prefix hack

This commit is contained in:
Jakob Ketterl 2021-03-03 15:24:18 +01:00
parent 37d89c074b
commit c0b7cf5f8d
7 changed files with 23 additions and 65 deletions

View File

@ -1,7 +1,7 @@
<div class="webrx-top-container"> <div class="webrx-top-container">
<div class="webrx-top-bar"> <div class="webrx-top-bar">
<a href="https://www.openwebrx.de/" target="_blank"><img src="${assets_prefix}static/gfx/openwebrx-top-logo.png" class="webrx-top-logo" alt="OpenWebRX Logo"/></a> <a href="https://www.openwebrx.de/" target="_blank"><img src="${document_root}static/gfx/openwebrx-top-logo.png" class="webrx-top-logo" alt="OpenWebRX Logo"/></a>
<img class="webrx-rx-avatar openwebrx-photo-trigger" src="${assets_prefix}static/gfx/openwebrx-avatar.png" alt="Receiver avatar"/> <img class="webrx-rx-avatar openwebrx-photo-trigger" src="${document_root}static/gfx/openwebrx-avatar.png" alt="Receiver avatar"/>
<div class="webrx-rx-texts openwebrx-photo-trigger"> <div class="webrx-rx-texts openwebrx-photo-trigger">
<h1 class="webrx-rx-title">${receiver_name}</h1> <h1 class="webrx-rx-title">${receiver_name}</h1>
<div class="webrx-rx-desc">${receiver_location} | Loc: ${locator}, ASL: ${receiver_asl} m</div> <div class="webrx-rx-desc">${receiver_location} | Loc: ${locator}, ASL: ${receiver_asl} m</div>
@ -10,8 +10,8 @@
<div class="button" data-toggle-panel="openwebrx-panel-status"><span class="sprite sprite-panel-status"></span><br/>Status</div> <div class="button" data-toggle-panel="openwebrx-panel-status"><span class="sprite sprite-panel-status"></span><br/>Status</div>
<div class="button" data-toggle-panel="openwebrx-panel-log"><span class="sprite sprite-panel-log"></span><br/>Log</div> <div class="button" data-toggle-panel="openwebrx-panel-log"><span class="sprite sprite-panel-log"></span><br/>Log</div>
<div class="button" data-toggle-panel="openwebrx-panel-receiver"><span class="sprite sprite-panel-receiver"></span><br/>Receiver</div> <div class="button" data-toggle-panel="openwebrx-panel-receiver"><span class="sprite sprite-panel-receiver"></span><br/>Receiver</div>
<a class="button" href="${assets_prefix}map" target="openwebrx-map"><span class="sprite sprite-panel-map"></span><br/>Map</a> <a class="button" href="${document_root}map" target="openwebrx-map"><span class="sprite sprite-panel-map"></span><br/>Map</a>
<a class="button" href="${assets_prefix}settings" target="openwebrx-settings"><span class="sprite sprite-panel-settings"></span><br/>Settings</a> <a class="button" href="${document_root}settings" target="openwebrx-settings"><span class="sprite sprite-panel-settings"></span><br/>Settings</a>
</section> </section>
</div> </div>
<div class="openwebrx-description-container"> <div class="openwebrx-description-container">

View File

@ -2,11 +2,11 @@
<html> <html>
<head> <head>
<title>OpenWebRX Settings</title> <title>OpenWebRX Settings</title>
<link rel="shortcut icon" type="image/x-icon" href="${assets_prefix}static/favicon.ico" /> <link rel="shortcut icon" type="image/x-icon" href="${document_root}static/favicon.ico" />
<link rel="stylesheet" href="${assets_prefix}static/css/bootstrap.min.css" /> <link rel="stylesheet" href="${document_root}static/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="${assets_prefix}static/css/admin.css" /> <link rel="stylesheet" type="text/css" href="${document_root}static/css/admin.css" />
<script src="https://unpkg.com/location-picker/dist/location-picker.min.js"></script> <script src="https://unpkg.com/location-picker/dist/location-picker.min.js"></script>
<script src="${assets_prefix}compiled/settings.js"></script> <script src="${document_root}compiled/settings.js"></script>
<meta charset="utf-8"> <meta charset="utf-8">
</head> </head>
<body> <body>

View File

@ -68,16 +68,10 @@ class SettingsFormController(AuthorizationMixin, WebpageController, metaclass=AB
def indexAction(self): def indexAction(self):
self.serve_template("settings/general.html", **self.template_variables()) self.serve_template("settings/general.html", **self.template_variables())
def header_variables(self):
variables = super().header_variables()
variables["assets_prefix"] = "../"
return variables
def template_variables(self): def template_variables(self):
variables = super().template_variables() variables = super().template_variables()
variables["content"] = self.render_sections() variables["content"] = self.render_sections()
variables["title"] = self.getTitle() variables["title"] = self.getTitle()
variables["assets_prefix"] = "../"
return variables return variables
def parseFormData(self): def parseFormData(self):

View File

@ -10,11 +10,6 @@ logger = logging.getLogger(__name__)
class BookmarksController(AuthorizationMixin, WebpageController): class BookmarksController(AuthorizationMixin, WebpageController):
def header_variables(self):
variables = super().header_variables()
variables["assets_prefix"] = "../"
return variables
def template_variables(self): def template_variables(self):
variables = super().template_variables() variables = super().template_variables()
variables["bookmarks"] = self.render_table() variables["bookmarks"] = self.render_table()

View File

@ -13,16 +13,10 @@ from abc import ABCMeta
class SdrDeviceListController(AuthorizationMixin, WebpageController): class SdrDeviceListController(AuthorizationMixin, WebpageController):
def header_variables(self):
variables = super().header_variables()
variables["assets_prefix"] = "../"
return variables
def template_variables(self): def template_variables(self):
variables = super().template_variables() variables = super().template_variables()
variables["content"] = self.render_devices() variables["content"] = self.render_devices()
variables["title"] = "SDR device settings" variables["title"] = "SDR device settings"
variables["assets_prefix"] = "../"
return variables return variables
def render_devices(self): def render_devices(self):
@ -134,16 +128,6 @@ class SdrDeviceController(SdrFormController):
def getTitle(self): def getTitle(self):
return self.device["name"] return self.device["name"]
def header_variables(self):
variables = super().header_variables()
variables["assets_prefix"] = "../../"
return variables
def template_variables(self):
variables = super().template_variables()
variables["assets_prefix"] = "../../"
return variables
def render_sections(self): def render_sections(self):
return super().render_sections() + self.render_profile_list(self.device["profiles"]) return super().render_sections() + self.render_profile_list(self.device["profiles"])
@ -189,16 +173,6 @@ class NewSdrDeviceController(SettingsFormController):
self.stack.addLayer(0, id_layer) self.stack.addLayer(0, id_layer)
self.stack.addLayer(1, self.data_layer) self.stack.addLayer(1, self.data_layer)
def header_variables(self):
variables = super().header_variables()
variables["assets_prefix"] = "../../"
return variables
def template_variables(self):
variables = super().template_variables()
variables["assets_prefix"] = "../../"
return variables
def getSections(self): def getSections(self):
return [ return [
Section( Section(
@ -251,16 +225,6 @@ class SdrProfileController(SdrFormController):
def getTitle(self): def getTitle(self):
return self.profile["name"] return self.profile["name"]
def header_variables(self):
variables = super().header_variables()
variables["assets_prefix"] = "../../../"
return variables
def template_variables(self):
variables = super().template_variables()
variables["assets_prefix"] = "../../../"
return variables
def indexAction(self): def indexAction(self):
if self.profile is None: if self.profile is None:
self.send_response("profile not found", code=404) self.send_response("profile not found", code=404)

View File

@ -19,14 +19,19 @@ class TemplateController(Controller):
class WebpageController(TemplateController): class WebpageController(TemplateController):
def get_document_root(self):
path_parts = [part for part in self.request.path[1:].split("/")]
levels = max(0, len(path_parts) - 1)
return "../" * levels
def header_variables(self): def header_variables(self):
variables = {"assets_prefix": ""} variables = {"document_root": self.get_document_root()}
variables.update(ReceiverDetails().__dict__()) variables.update(ReceiverDetails().__dict__())
return variables return variables
def template_variables(self): def template_variables(self):
header = self.render_template("include/header.include.html", **self.header_variables()) header = self.render_template("include/header.include.html", **self.header_variables())
return {"header": header} return {"header": header, "document_root": self.get_document_root()}
class IndexController(WebpageController): class IndexController(WebpageController):

View File

@ -40,23 +40,23 @@ class RequestHandler(BaseHTTPRequestHandler):
logger.debug("%s - - [%s] %s", self.address_string(), self.log_date_time_string(), format % args) logger.debug("%s - - [%s] %s", self.address_string(), self.log_date_time_string(), format % args)
def do_GET(self): def do_GET(self):
self.router.route(self, self.get_request("GET")) self.router.route(self, self._build_request("GET"))
def do_POST(self): def do_POST(self):
self.router.route(self, self.get_request("POST")) self.router.route(self, self._build_request("POST"))
def do_DELETE(self): def do_DELETE(self):
self.router.route(self, self.get_request("DELETE")) self.router.route(self, self._build_request("DELETE"))
def get_request(self, method): def _build_request(self, method):
url = urlparse(self.path) return Request(self.path, method, self.headers)
return Request(url, method, self.headers)
class Request(object): class Request(object):
def __init__(self, url, method, headers): def __init__(self, url, method, headers):
self.path = url.path parsed_url = urlparse(url)
self.query = parse_qs(url.query) self.path = parsed_url.path
self.query = parse_qs(parsed_url.query)
self.matches = None self.matches = None
self.method = method self.method = method
self.headers = headers self.headers = headers