From 3814200452817da69c1ad928b8eb847df988ea6f Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Wed, 3 Mar 2021 23:07:41 +0100 Subject: [PATCH] implement device and profile deletion --- owrx/controllers/settings/sdr.py | 20 +++++++++++++++++++- owrx/http.py | 6 ++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/owrx/controllers/settings/sdr.py b/owrx/controllers/settings/sdr.py index 0115bfb..db40bc8 100644 --- a/owrx/controllers/settings/sdr.py +++ b/owrx/controllers/settings/sdr.py @@ -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): diff --git a/owrx/http.py b/owrx/http.py index b26ca46..51a6837 100644 --- a/owrx/http.py +++ b/owrx/http.py @@ -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"}),