aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--apioforum/db.py4
-rw-r--r--apioforum/static/style.css4
-rw-r--r--apioforum/templates/config_thread.html19
-rw-r--r--apioforum/templates/view_thread.html54
-rw-r--r--apioforum/thread.py52
5 files changed, 105 insertions, 28 deletions
diff --git a/apioforum/db.py b/apioforum/db.py
index e09b8d2..6ec65b6 100644
--- a/apioforum/db.py
+++ b/apioforum/db.py
@@ -289,9 +289,11 @@ CREATE TABLE wiki_pages (
);
ALTER TABLE role_config ADD COLUMN p_edit_wiki INT NOT NULL DEFAULT 1
""",
+"""
+ALTER TABLE polls ADD COLUMN closed INT NOT NULL DEFAULT 0;
+""",
]
-
def init_db():
db = get_db()
version = db.execute("PRAGMA user_version;").fetchone()[0]
diff --git a/apioforum/static/style.css b/apioforum/static/style.css
index 91ce6b0..24e740e 100644
--- a/apioforum/static/style.css
+++ b/apioforum/static/style.css
@@ -48,7 +48,7 @@ summary { user-select: none; }
text-decoration: underline;
}
.post-heading-em { font-weight: bold; }
-.post-content { overflow: auto; }
+.post-content { overflow: auto; clear: both; }
.post-content * { margin-bottom: 8px; margin-top: 8px; }
.post-content > *:first-child { margin-top: 2px }
.post-content > *:last-child { margin-bottom: 0}
@@ -534,7 +534,7 @@ sitelen {
@font-face {
font-family: nasin-nanpa;
- src: local(nasin-nanpa), url("nasin-nanpa.otf") format("opentype");
+ src: url("nasin-nanpa.otf") format("opentype");
}
.wiki-body {
diff --git a/apioforum/templates/config_thread.html b/apioforum/templates/config_thread.html
index 6d4b7f2..bb1e605 100644
--- a/apioforum/templates/config_thread.html
+++ b/apioforum/templates/config_thread.html
@@ -74,15 +74,28 @@
<label for="polloptions">options (one per line)</label>
<textarea name="polloptions" id="polloptions"></textarea>
</fieldset>
- <p>important: once a poll is created, you will not be able to modify it except to delete it entirely</p>
+ <p>once a poll is created, you will not be able to modify it except to close it, or to delete it entirely</p>
<input type="submit" value="create">
</form>
{% else %}
-<h2>delete poll</h2>
-<p>there is already a poll attached to this {{type}}. you can delete it, which will allow you to create a new one, but this will erase all existing votes and data for the current poll.</p>
+<h2>poll operations</h2>
+<p>there is already a poll attached to this {{type}}.</p>
+{% if poll.closed %}
+<p>it has been closed already, and may not be reopened.</p>
+{% else %}
+<p>you can close it, which will prevent all further votes. you cannot reopen the poll after it has been closed.</p>
+<form action="{{url_for('thread.close_poll',thread_id=thread.id)}}" method="post">
+ <input type="submit" value="confirm: close poll">
+</form>
+{% endif %}
+
+<p>you can {% if not poll.closed %}also{% endif %} delete it, which will allow you to create a new one, but this will erase all existing votes and data for the current poll.</p>
+
<form action="{{url_for('thread.delete_poll',thread_id=thread.id)}}" method="post">
<input type="submit" value="confirm: delete poll">
</form>
+
+
{% endif %}
{% endif %}
diff --git a/apioforum/templates/view_thread.html b/apioforum/templates/view_thread.html
index 3b25275..7e35db2 100644
--- a/apioforum/templates/view_thread.html
+++ b/apioforum/templates/view_thread.html
@@ -97,32 +97,46 @@
{{ pagination_nav(page,max_pageno,'thread.view_thread',thread_id=thread.id,bottom=True,fragment="replies") }}
{% elif g.user and has_permission(thread.forum, g.user, "p_reply_threads") %}
{% if thread.locked and not has_permission(thread.forum, g.user, "p_manage_threads") %}
- <p>this thread is locked, and may not recieve further replies</p>
+ <p>this thread is locked, and may not receive further replies</p>
{% else %}
<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 reply 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>
+ <textarea class="new-post-box" placeholder="your post here..." name="content"></textarea>
+ {% if poll %}
+ <fieldset>
+ <legend>poll: {{poll.title}}</legend>
+ {% if poll.closed %}
+ <p>this poll has been closed, and may not receive 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 0db693f..4e3b326 100644
--- a/apioforum/thread.py
+++ b/apioforum/thread.py
@@ -247,7 +247,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:
@@ -271,6 +307,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)
@@ -476,6 +516,9 @@ def config_thread(thread_id):
thread = db.execute("select * from threads where id = ?",(thread_id,)).fetchone()
thread_tags = [r['tag'] for r in db.execute("select tag from thread_tags where thread = ?",(thread_id,)).fetchall()]
avail_tags = get_avail_tags(thread['forum'])
+ if thread['poll'] is not None:
+ poll = db.execute("select * from polls where id = ?",(thread['poll'],)).fetchone()
+
err = None
if g.user is None:
err = "you need to be logged in to do that"
@@ -533,5 +576,10 @@ def config_thread(thread_id):
else:
return redirect(url_for("thread.view_thread",thread_id=thread_id))
- return render_template("config_thread.html", thread=thread,thread_tags=thread_tags,avail_tags=avail_tags)
+ return render_template("config_thread.html",
+ thread=thread,
+ thread_tags=thread_tags,
+ avail_tags=avail_tags,
+ poll=poll,
+ )