From 8572d5de13aa97bbc46585f8be8eecab0ab79667 Mon Sep 17 00:00:00 2001 From: rebecca Date: Sun, 8 Nov 2026 15:19:20 +0000 Subject: add closing of polls --- apioforum/db.py | 4 +++ apioforum/templates/view_thread.html | 50 +++++++++++++++++++++++------------- apioforum/thread.py | 42 +++++++++++++++++++++++++++++- 3 files changed, 77 insertions(+), 19 deletions(-) diff --git a/apioforum/db.py b/apioforum/db.py index ead4e5a..61f1bc3 100644 --- a/apioforum/db.py +++ b/apioforum/db.py @@ -261,6 +261,10 @@ ALTER TABLE users ADD COLUMN banreason TEXT; """ ALTER TABLE threads ADD COLUMN locked INT NOT NULL DEFAULT 0; """, +"", "", # put wiki stuff here when merging +""" +ALTER TABLE polls ADD COLUMN closed INT NOT NULL DEFAULT 0; +""", ] diff --git a/apioforum/templates/view_thread.html b/apioforum/templates/view_thread.html index 1a74f60..0dd2fde 100644 --- a/apioforum/templates/view_thread.html +++ b/apioforum/templates/view_thread.html @@ -79,27 +79,41 @@
{% if thread.locked %}

this thread is locked, but you can reply to it anyway

{% endif %} - {% if poll and has_permission(thread.forum, g.user, "p_vote") %} -
- poll: {{poll.title}} -

if you want, you can submit a vote along with this post. if you have previously voted - on this poll, your previous vote will be changed

+ {% if poll %} +
+ poll: {{poll.title}} + {% if poll.closed %} +

this poll has closed, and may not recieve further votes

+ {% elif not has_permission(thread.forum, g.user, "p_vote") %} +

you don't have permission to vote on this poll

+ {% else %} +

+ {% if has_voted %} + you have already voted, but you can change or retract your vote at any time, as long as the poll is still open. + {% else %} + you will be able to change or retract your vote at any time, as long as the poll is still open. + {% endif %}

- - + + {% if has_voted %} + + {% else %} + + {% endif %} - {% if has_voted %} -
- - - {% endif %} + {% if has_voted %} +
+ + + {% endif %} - {% for opt in poll.options %} -
- - - {% endfor %} -
+ {% for opt in poll.options %} +
+ + + {% endfor %} + {% endif %} +
{% endif %}
diff --git a/apioforum/thread.py b/apioforum/thread.py index 3c4a3a3..6ef6122 100644 --- a/apioforum/thread.py +++ b/apioforum/thread.py @@ -229,7 +229,43 @@ def delete_poll(thread_id): db.commit() flash("poll deleted successfully") return success - + +@bp.route("//close_poll", methods=["POST"]) +def close_poll(thread_id): + fail = redirect(url_for('thread.config_thread',thread_id=thread_id)) + success = redirect(url_for('thread.view_thread',thread_id=thread_id)) + err = None + db = get_db() + thread = thread_info(thread_id) + + if thread is None: + err = "that thread does not exist" + elif g.user is None: + err = "you need to be logged in to do that" + elif g.user != thread['creator'] and not \ + has_permission(thread['forum'], g.user, "p_manage_threads"): + err = "you can only close polls on threads that you own" + elif thread['poll'] is None: + err = "there is no poll to close on this thread" + + if err is not None: + flash(err) + return fail + + pollid = thread['poll'] + poll = db.execute("SELECT * FROM polls WHERE id = ?", (pollid,)).fetchone() + if poll['closed']: + flash("this poll has already been closed") + return fail + + db.execute("UPDATE polls SET closed = 1 WHERE id = ?", (pollid,)) + db.commit() + + import random + adverb = random.choice(["clamorously","clandestinely","clasically","cleanly","clearly","clerically","cleverly","climatically","clinically","closely","cloyingly","clumsily"]) + flash("poll closed "+adverb) + return success + @bp.route("//create_post", methods=("POST",)) def create_post(thread_id): if g.user is None: @@ -253,6 +289,10 @@ def create_post(thread_id): else: vote_id = None if thread['poll'] is not None: + poll = db.execute("SELECT * FROM polls WHERE id = ?",(thread['poll'],)).fetchone() + if poll['closed']: + flash("this poll has been closed and may not receive further votes") + return redirect(url_for('thread.view_thread',thread_id=thread_id)) pollval = request.form.get('poll') try: vote_id = register_vote(thread,pollval) -- cgit v1.2.3