implement bookmark deletion
This commit is contained in:
@ -99,3 +99,8 @@ class Bookmarks(object):
|
||||
|
||||
def addBookmark(self, bookmark: Bookmark):
|
||||
self.bookmarks.append(bookmark)
|
||||
|
||||
def removeBookmark(self, bookmark: Bookmark):
|
||||
if bookmark not in self.bookmarks:
|
||||
return
|
||||
self.bookmarks.remove(bookmark)
|
||||
|
@ -60,7 +60,7 @@ class BookmarksController(AuthorizationMixin, WebpageController):
|
||||
<td class="frequency">{frequency}</td>
|
||||
<td data-value="{modulation}">{modulation_name}</td>
|
||||
<td>
|
||||
<div class="btn btn-sm btn-danger bookmark-delete">delete</div>
|
||||
<button class="btn btn-sm btn-danger bookmark-delete">delete</button>
|
||||
</td>
|
||||
</tr>
|
||||
""".format(
|
||||
@ -111,5 +111,16 @@ class BookmarksController(AuthorizationMixin, WebpageController):
|
||||
except json.JSONDecodeError:
|
||||
self.send_response("{}", content_type="application/json", code=400)
|
||||
|
||||
def delete(self):
|
||||
bookmark_id = int(self.request.matches.group(1))
|
||||
bookmark = self._findBookmark(bookmark_id)
|
||||
if bookmark is None:
|
||||
self.send_response("{}", content_type="application/json", code=404)
|
||||
return
|
||||
bookmarks = Bookmarks.getSharedInstance()
|
||||
bookmarks.removeBookmark(bookmark)
|
||||
bookmarks.store()
|
||||
self.send_response("{}", content_type="application/json", code=200)
|
||||
|
||||
def indexAction(self):
|
||||
self.serve_template("settings/bookmarks.html", **self.template_variables())
|
||||
|
@ -35,6 +35,9 @@ class RequestHandler(BaseHTTPRequestHandler):
|
||||
def do_POST(self):
|
||||
self.router.route(self, self.get_request("POST"))
|
||||
|
||||
def do_DELETE(self):
|
||||
self.router.route(self, self.get_request("DELETE"))
|
||||
|
||||
def get_request(self, method):
|
||||
url = urlparse(self.path)
|
||||
return Request(url, method, self.headers)
|
||||
@ -112,6 +115,7 @@ class Router(object):
|
||||
StaticRoute("/settings/bookmarks", BookmarksController),
|
||||
StaticRoute("/settings/bookmarks", BookmarksController, method="POST", options={"action": "new"}),
|
||||
RegexRoute("/settings/bookmarks/(.+)", BookmarksController, method="POST", options={"action": "update"}),
|
||||
RegexRoute("/settings/bookmarks/(.+)", BookmarksController, method="DELETE", options={"action": "delete"}),
|
||||
StaticRoute("/login", SessionController, options={"action": "loginAction"}),
|
||||
StaticRoute("/login", SessionController, method="POST", options={"action": "processLoginAction"}),
|
||||
StaticRoute("/logout", SessionController, options={"action": "logoutAction"}),
|
||||
|
Reference in New Issue
Block a user