aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--apioforum/db.py4
-rw-r--r--apioforum/templates/view_thread.html50
-rw-r--r--apioforum/thread.py42
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 @@
<form class="new-post" action="{{url_for('thread.create_post',thread_id=thread.id)}}" method="POST">
{% if thread.locked %}<p>this thread is locked, but you can reply to it anyway</p>{% endif %}
<textarea class="new-post-box" placeholder="your post here..." name="content"></textarea>
- {% if poll and has_permission(thread.forum, g.user, "p_vote") %}
- <fieldset>
- <legend>poll: {{poll.title}}</legend>
- <p>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</p>
+ {% if poll %}
+ <fieldset>
+ <legend>poll: {{poll.title}}</legend>
+ {% if poll.closed %}
+ <p>this poll has closed, and may not recieve further votes</p>
+ {% elif not has_permission(thread.forum, g.user, "p_vote") %}
+ <p>you don't have permission to vote on this poll</p>
+ {% else %}
+ <p>
+ {% 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 %}</p>
- <input type="radio" id="dontvote" name="poll" value="dontvote" checked>
- <label for="dontvote">do not submit any vote at the moment</label>
+ <input type="radio" id="dontvote" name="poll" value="dontvote" checked>
+ {% if has_voted %}
+ <label for="dontvote">keep my vote as it is, for the moment</label>
+ {% else %}
+ <label for="dontvote">do not submit any vote at the moment</label>
+ {% endif %}
- {% if has_voted %}
- <br>
- <input type="radio" id="retractvote" name="poll" value="retractvote">
- <label for="retractvote">clear current vote</label>
- {% endif %}
+ {% if has_voted %}
+ <br>
+ <input type="radio" id="retractvote" name="poll" value="retractvote">
+ <label for="retractvote">rectract my vote</label>
+ {% endif %}
- {% for opt in poll.options %}
- <br>
- <input type="radio" id="option_{{opt.option_idx}}" name="poll" value="{{opt.option_idx}}">
- <label for="option_{{opt.option_idx}}">#{{opt.option_idx}} - {{opt.text}}</label>
- {% endfor %}
- </fieldset>
+ {% for opt in poll.options %}
+ <br>
+ <input type="radio" id="option_{{opt.option_idx}}" name="poll" value="{{opt.option_idx}}">
+ <label for="option_{{opt.option_idx}}">#{{opt.option_idx}} - {{opt.text}}</label>
+ {% endfor %}
+ {% endif %}
+ </fieldset>
{% endif %}
<input type="submit" value="yes">
</form>
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("/<int:thread_id>/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("/<int:thread_id>/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)