aboutsummaryrefslogtreecommitdiffstats
path: root/app.py
diff options
context:
space:
mode:
authorMedMan Dev <dev@medman.local>2026-10-30 15:59:15 +0000
committerMedMan Dev <dev@medman.local>2026-10-30 15:59:15 +0000
commitec5f9cf92d6553d8b80b313ef0628e44759dce8b (patch)
treea2cf569eed8ef7746b4b9820d580d8446ef57df4 /app.py
parente4f56bf708face7f6e6187494f6a95d39f97dc99 (diff)
downloadmedman-ec5f9cf92d6553d8b80b313ef0628e44759dce8b.tar.gz
Add tag rename (pen icon) with PATCH endpoint
- Pen icon (✎) next to the remove (×) on each tag in the left menu - Opens a dialog with a text input for the new name - New PATCH /api/tags/<tid> endpoint renames the tag and merges duplicates (moves all ftags to an existing tag if name collides) - All tagged items reflect the rename immediately
Diffstat (limited to 'app.py')
-rwxr-xr-xapp.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/app.py b/app.py
index 02f74ad..1d3fe75 100755
--- a/app.py
+++ b/app.py
@@ -517,6 +517,29 @@ def a_tag_del(tid: int):
return jsonify({"ok": True})
+@app.route("/api/tags/<int:tid>", methods=["PATCH"])
+def a_tag_rename(tid: int):
+ d = request.get_json() or {}
+ n = (d.get("name") or "").strip().lower()
+ if not n:
+ return jsonify({"error": "name required"}), 400
+ db = gdb()
+ existing = db.execute("SELECT id FROM tags WHERE name = ? AND id != ?",
+ (n, tid)).fetchone()
+ if existing:
+ db.execute("UPDATE OR IGNORE ftags SET tid = ? WHERE tid = ?",
+ (existing["id"], tid))
+ db.execute("DELETE FROM ftags WHERE tid = ?", (tid,))
+ db.execute("DELETE FROM tags WHERE id = ?", (tid,))
+ result_id = existing["id"]
+ else:
+ db.execute("UPDATE tags SET name = ? WHERE id = ?", (n, tid))
+ result_id = tid
+ db.commit()
+ t = db.execute("SELECT id, name FROM tags WHERE id = ?", (result_id,)).fetchone()
+ db.close()
+ return jsonify(dict(t))
+
# ============================================================================
# Routes — file tags
# ============================================================================