summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorubq323 <ubq323>2021-06-26 01:05:28 +0000
committerubq323 <ubq323>2021-06-26 01:05:28 +0000
commita1660cad33f03828e2c74d8f083ad6490ea0da7f (patch)
tree3237418f6317d0c9bbe765c172d47ef76304e9e6
parentccb0394a52050f21701c856239f999ede529f71b (diff)
displaying of votes on posts
-rw-r--r--apioforum/static/style.css6
-rw-r--r--apioforum/templates/common.html7
-rw-r--r--apioforum/templates/view_thread.html20
-rw-r--r--apioforum/thread.py26
4 files changed, 47 insertions, 12 deletions
diff --git a/apioforum/static/style.css b/apioforum/static/style.css
index 3815860..6178dd9 100644
--- a/apioforum/static/style.css
+++ b/apioforum/static/style.css
@@ -16,8 +16,8 @@ body { font-family: sans-serif; word-wrap: break-word; }
}
.post:last-of-type { border-bottom: 1px solid black; }
-.post-heading { font-size: smaller; }
-.post-heading,a.username {
+.post-heading,.post-footer { font-size: smaller; }
+.post-heading,.post-footer,a.username {
color: hsl(0,0%,25%);
}
a.username {
@@ -32,6 +32,8 @@ a.username {
.post-heading-a { margin-left: 0.2em }
.post-heading-b { float: right; margin-right: 0.5em }
+.post-footer { margin-left: 0.2em; font-style: italic; }
+
.post-anchor-link { color: hsl(0,0%,25%); }
.thread-top-bar, .user-top-bar {
diff --git a/apioforum/templates/common.html b/apioforum/templates/common.html
index 8fcf5fe..3321085 100644
--- a/apioforum/templates/common.html
+++ b/apioforum/templates/common.html
@@ -6,7 +6,7 @@
{{url_for('thread.view_thread', thread_id=post.thread)}}#post_{{post.id}}
{%- endmacro %}
-{% macro disp_post(post, buttons=False) %}
+{% macro disp_post(post, buttons=False, footer=None) %}
<div class="post" id="post_{{post.id}}">
<div class="post-heading">
<span class="post-heading-a">
@@ -34,6 +34,11 @@
<div class="post-content md">
{{ post.content|md|safe }}
</div>
+ {% if footer %}
+ <div class="post-footer">
+ {{ footer }}
+ </div>
+ {% endif %}
</div>
{% endmacro %}
diff --git a/apioforum/templates/view_thread.html b/apioforum/templates/view_thread.html
index d45b36b..513ee59 100644
--- a/apioforum/templates/view_thread.html
+++ b/apioforum/templates/view_thread.html
@@ -29,7 +29,25 @@
<div class="posts">
{% for post in posts %}
- {{ disp_post(post, True) }}
+ {% if votes[post.id] %}
+
+ {% set vote = votes[post.id] %}
+ {% set option_idx = vote.option_idx %}
+ {% set option = poll.options[option_idx-1] %}
+
+ {% set footer %}
+ {% if vote.current %}
+ {{post.author}} votes for {{option_idx}}: {{option.text}}
+ {% else %}
+ {{post.author}} voted for {{option_idx}}: {{option.text}}, but later changed their vote
+ {% endif %}
+ {% endset %}
+
+ {{ disp_post(post, buttons=True, footer=footer) }}
+
+ {% else %}
+ {{ disp_post(post, buttons=True) }}
+ {% endif %}
{% endfor %}
</div>
{% if g.user %}
diff --git a/apioforum/thread.py b/apioforum/thread.py
index 559f9b2..7d068c4 100644
--- a/apioforum/thread.py
+++ b/apioforum/thread.py
@@ -18,10 +18,11 @@ def view_thread(thread_id):
if thread is None:
abort(404)
else:
- posts = db.execute(
- "SELECT * FROM posts WHERE thread = ? ORDER BY created ASC;",
- (thread_id,)
- ).fetchall()
+ posts = db.execute("""
+ SELECT * FROM posts
+ WHERE posts.thread = ?
+ ORDER BY created ASC;
+ """,(thread_id,)).fetchall()
tags = db.execute(
"""SELECT tags.* FROM tags
INNER JOIN thread_tags ON thread_tags.tag = tags.id
@@ -34,11 +35,20 @@ def view_thread(thread_id):
poll = {}
poll.update(poll_row)
poll['options'] = options
+ votes = {}
+ # todo: optimise this somehow
+ for post in posts:
+ if post['vote'] is not None:
+ votes[post['id']] = db.execute("SELECT * FROM votes WHERE id = ?",(post['vote'],)).fetchone()
- return render_template("view_thread.html",posts=posts,thread=thread,tags=tags,poll=poll)
-
-
-
+ return render_template(
+ "view_thread.html",
+ posts=posts,
+ thread=thread,
+ tags=tags,
+ poll=poll,
+ votes=votes
+ )
def register_vote(thread,pollval):
if pollval is None or pollval == 'dontvote':