From ddcaf27ec55edbf69c6f957680d23e5ee34f724f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=BCller?= Date: Mon, 30 Jul 2018 15:40:16 +0200 Subject: [PATCH] Add ability to add and remove tags in edit mode --- soundboard.py | 18 ++++++++++++++++++ templates/index.html | 3 ++- templates/tags_add.html | 13 +++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 templates/tags_add.html diff --git a/soundboard.py b/soundboard.py index 00e8237..8d789fc 100644 --- a/soundboard.py +++ b/soundboard.py @@ -178,3 +178,21 @@ WHERE button.id IN ( sounds = queryDB(query, tags.split(",")) return jsonify([sound["file"].split(".")[0] for sound in sounds]) + +@app.route("/tags/add/", methods=["GET", "POST"]) +def tags_add(): + if request.method == "POST": + if not request.form.get("cancel") and request.form.get("tag") is not None: + queryDB("INSERT OR REPLACE INTO tag (name) VALUES (?)", (request.form.get("tag"),)) + getDB().commit() + + return redirect("/edit") + + return render_template("tags_add.html") + +@app.route("/tags/delete/") +def tags_delete(name): + queryDB("DELETE FROM tag WHERE name = ?", (name,)) + getDB().commit() + + return redirect("/edit") diff --git a/templates/index.html b/templates/index.html index 168cc9f..751c268 100644 --- a/templates/index.html +++ b/templates/index.html @@ -47,8 +47,9 @@