forked from server/soundboard
Add ability to add and remove tags in edit mode
This commit is contained in:
parent
6d36a62e18
commit
ddcaf27ec5
@ -178,3 +178,21 @@ WHERE button.id IN (
|
|||||||
sounds = queryDB(query, tags.split(","))
|
sounds = queryDB(query, tags.split(","))
|
||||||
|
|
||||||
return jsonify([sound["file"].split(".")[0] for sound in sounds])
|
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")
|
||||||
|
|||||||
@ -47,8 +47,9 @@
|
|||||||
<div id="reset">✕</div>
|
<div id="reset">✕</div>
|
||||||
<ul class="tags">
|
<ul class="tags">
|
||||||
{% for tag in 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 %}
|
{% endfor %}
|
||||||
|
{%- if edit %}<li><a href="/tags/add/" tabindex="-1">+</a></li>{% endif -%}
|
||||||
</ul>
|
</ul>
|
||||||
</div><!--
|
</div><!--
|
||||||
{% for sound in sounds %}
|
{% for sound in sounds %}
|
||||||
|
|||||||
13
templates/tags_add.html
Normal file
13
templates/tags_add.html
Normal 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 %}
|
||||||
Loading…
x
Reference in New Issue
Block a user