Add ability to add and remove tags in edit mode

This commit is contained in:
Martin Müller 2018-07-30 15:40:16 +02:00
parent 6d36a62e18
commit ddcaf27ec5
3 changed files with 33 additions and 1 deletions

View File

@ -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/<path:name>")
def tags_delete(name):
queryDB("DELETE FROM tag WHERE name = ?", (name,))
getDB().commit()
return redirect("/edit")

View File

@ -47,8 +47,9 @@
<div id="reset"></div>
<ul class="tags">
{% for tag in tags %}
<li><a href="#" tabindex="-1">{{ tag.name }}</a></li>
<li><a href="#" tabindex="-1">{{ tag.name }}</a>{% if edit %} <a href="/tags/delete/{{ tag.name }}"></a>{% endif %}</li>
{% endfor %}
{%- if edit %}<li><a href="/tags/add/" tabindex="-1">+</a></li>{% endif -%}
</ul>
</div><!--
{% for sound in sounds %}

13
templates/tags_add.html Normal file
View File

@ -0,0 +1,13 @@
{% extends "base.html" %}
{% block navigation %}
{% endblock %}
{% block content %}
<div class="editform">
<h1>Add tag</h1>
<form action="{{ request.path }}" method="POST">
<input type="text" name="tag" placeholder="tag name" />
<input type="submit" name="cancel" value="Cancel" />
<input type="submit" name="submit" value="Add" />
</form>
</div>
{% endblock %}