diff options
Diffstat (limited to 'apioforum/forum.py')
-rw-r--r-- | apioforum/forum.py | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/apioforum/forum.py b/apioforum/forum.py index c3bf1c0..c44afe6 100644 --- a/apioforum/forum.py +++ b/apioforum/forum.py @@ -25,16 +25,20 @@ bp = Blueprint("forum", __name__, url_prefix="/") def not_actual_index(): return redirect("/1") -def get_avail_tags(forum_id): +def get_avail_tags(forum_id,all=False): db = get_db() + enabled_filter = "" + if not all: + enabled_filter = "AND enabled = 1" tags = db.execute(""" WITH RECURSIVE fs AS (SELECT * FROM forums WHERE id = ? UNION ALL SELECT forums.* FROM forums, fs WHERE fs.parent=forums.id) SELECT * FROM tags - WHERE tags.forum in (SELECT id FROM fs) - ORDER BY id; + WHERE tags.forum in (SELECT id FROM fs)""" + enabled_filter + \ + """ + ORDER BY forum, id; """,(forum_id,)).fetchall() return tags @@ -486,6 +490,38 @@ def edit_forum(forum): def create_forum(forum): return forum_config_page(forum,create=True) +@forum_route("tags", methods=("GET","POST")) +@requires_bureaucrat +def edit_tags(forum): + db = get_db() + if request.method == "POST": + f = request.form + for t in db.execute("select * from tags where forum = ?;", (forum['id'],)): + id = "tag-" + str(t['id']) + "-" + if not id+'name' in f or not id+'fg' in f or not id+'bg' in f: + continue + enabled = id+'enabled' in f + db.execute("""update tags set + name = ?, text_colour = ?, bg_colour = ?, enabled = ? + where id = ? AND forum = ?;""", + (f[id+'name'], f[id+'fg'], f[id+'bg'], enabled, t['id'], forum['id'])) + db.commit() + flash("tags tagged tagfully") + return redirect(url_for("forum.view_forum",forum_id=forum['id'])) + tags = get_avail_tags(forum['id'],all=True) + return render_template("tags.html",forum=forum,tags=tags) + +@forum_route("tags/new", methods=("POST",)) +@requires_bureaucrat +def new_tag(forum): + db = get_db() + db.execute("""insert into tags + (name, text_colour, bg_colour, enabled, forum) values + ("new tag", "black", "white", 0, ?)""", (forum['id'],)) + db.commit() + flash("tag entagged tagously") + return redirect(url_for("forum.edit_tags",forum_id=forum['id'])) + #@forum_route("unlisted") #def view_unlisted(forum): # if not is_admin: abort(403) # why doesn't this fucking work |