implement device and profile deletion

This commit is contained in:
Jakob Ketterl 2021-03-03 23:07:41 +01:00
parent a9dbedee6d
commit 3814200452
2 changed files with 25 additions and 1 deletions

View File

@ -17,6 +17,7 @@ class SdrDeviceListController(AuthorizationMixin, WebpageController):
variables = super().template_variables()
variables["content"] = self.render_devices()
variables["title"] = "SDR device settings"
variables["modal"] = ""
return variables
def render_devices(self):
@ -196,6 +197,15 @@ class SdrDeviceController(SdrFormControllerWithModal):
def getModalConfirmUrl(self):
return "{}settings/deletesdr/{}".format(self.get_document_root(), quote(self.device_id))
def deleteDevice(self):
if self.device_id is None:
return self.send_response("device not found", code=404)
config = Config.get()
sdrs = config["sdrs"]
del sdrs[self.device_id]
config.store()
return self.send_redirect("{}settings/sdr".format(self.get_document_root()))
class NewSdrDeviceController(SettingsFormController):
def __init__(self, handler, request, options):
@ -287,10 +297,18 @@ class SdrProfileController(SdrFormControllerWithModal):
return "profile"
def getModalConfirmUrl(self):
return "{}settings/{}/deleteprofile/{}".format(
return "{}settings/sdr/{}/deleteprofile/{}".format(
self.get_document_root(), quote(self.device_id), quote(self.profile_id)
)
def deleteProfile(self):
if self.profile_id is None:
return self.send_response("profile not found", code=404)
config = Config.get()
del self.device["profiles"][self.profile_id]
config.store()
return self.send_redirect("{}settings/sdr".format(self.get_document_root()))
class NewProfileController(SdrFormController):
def __init__(self, handler, request, options):

View File

@ -130,6 +130,7 @@ class Router(object):
RegexRoute(
"^/settings/sdr/([^/]+)$", SdrDeviceController, method="POST", options={"action": "processFormData"}
),
RegexRoute("^/settings/deletesdr/([^/]+)$", SdrDeviceController, options={"action": "deleteDevice"}),
RegexRoute("^/settings/sdr/([^/]+)/newprofile$", NewProfileController),
RegexRoute(
"^/settings/sdr/([^/]+)/newprofile$",
@ -144,6 +145,11 @@ class Router(object):
method="POST",
options={"action": "processFormData"},
),
RegexRoute(
"^/settings/sdr/([^/]+)/deleteprofile/([^/]+)$",
SdrProfileController,
options={"action": "deleteProfile"},
),
StaticRoute("/settings/bookmarks", BookmarksController),
StaticRoute("/settings/bookmarks", BookmarksController, method="POST", options={"action": "new"}),
RegexRoute("^/settings/bookmarks/(.+)$", BookmarksController, method="POST", options={"action": "update"}),