add the "add bookmarks" function

This commit is contained in:
Jakob Ketterl
2021-02-14 16:21:09 +01:00
parent 9b1659d3dd
commit 29a161b7b7
7 changed files with 117 additions and 11 deletions

View File

@ -32,7 +32,7 @@ class BookmarksController(AuthorizationMixin, WebpageController):
)
return """
<table class="table bookmarks">
<table class="table">
<tr>
<th>Name</th>
<th class="frequency">Frequency</th>
@ -97,5 +97,19 @@ class BookmarksController(AuthorizationMixin, WebpageController):
except json.JSONDecodeError:
self.send_response("{}", content_type="application/json", code=400)
def new(self):
bookmarks = Bookmarks.getSharedInstance()
try:
data = json.loads(self.get_body())
# sanitize
data = {k: data[k] for k in ["name", "frequency", "modulation"]}
bookmark = Bookmark(data)
bookmarks.addBookmark(bookmark)
bookmarks.store()
self.send_response(json.dumps({"bookmark_id": id(bookmark)}), content_type="application/json", code=200)
except json.JSONDecodeError:
self.send_response("{}", content_type="application/json", code=400)
def indexAction(self):
self.serve_template("settings/bookmarks.html", **self.template_variables())