summaryrefslogtreecommitdiffhomepage
path: root/apioforum/forum.py
diff options
context:
space:
mode:
Diffstat (limited to 'apioforum/forum.py')
-rw-r--r--apioforum/forum.py32
1 files changed, 30 insertions, 2 deletions
diff --git a/apioforum/forum.py b/apioforum/forum.py
index fa6fcc8..56811e0 100644
--- a/apioforum/forum.py
+++ b/apioforum/forum.py
@@ -19,7 +19,7 @@ def view_forum():
db = get_db()
threads = db.execute(
"""SELECT threads.id, threads.title, threads.creator, threads.created,
- threads.updated, count(posts.id) as num_replies, max(posts.id), posts.author as last_user
+ threads.updated, threads.poll, count(posts.id) as num_replies, max(posts.id), posts.author as last_user
FROM threads
INNER JOIN posts ON posts.thread = threads.id
GROUP BY threads.id
@@ -27,6 +27,7 @@ def view_forum():
""").fetchall()
thread_tags = {}
preview_post = {}
+ thread_polls = {}
#todo: somehow optimise this
for thread in threads:
thread_tags[thread['id']] = db.execute(
@@ -39,10 +40,37 @@ def view_forum():
"""SELECT * FROM posts WHERE thread = ?
ORDER BY created DESC;
""",(thread['id'],)).fetchone()
+
+ if thread['poll'] is not None:
+ # todo: make this not be duplicated from thread.py
+ poll_row= db.execute("""
+ SELECT polls.*,total_vote_counts.total_votes FROM polls
+ LEFT OUTER JOIN total_vote_counts ON polls.id = total_vote_counts.poll
+ WHERE polls.id = ?;
+ """,(thread['poll'],)).fetchone()
+ options = db.execute("""
+ SELECT poll_options.*, vote_counts.num
+ FROM poll_options
+ LEFT OUTER JOIN vote_counts ON poll_options.poll = vote_counts.poll
+ AND poll_options.option_idx = vote_counts.option_idx
+ WHERE poll_options.poll = ?
+ ORDER BY option_idx asc;
+ """,(poll_row['id'],)).fetchall()
+
+ poll = {}
+ poll.update(poll_row)
+ poll['options'] = options
+ poll['total_votes']=poll['total_votes'] or 0
+ thread_polls[thread['id']]=poll
+
+
+
+
return render_template("view_forum.html",
threads=threads,
thread_tags=thread_tags,
- preview_post=preview_post
+ preview_post=preview_post,
+ thread_polls=thread_polls
)
@bp.route("/create_thread",methods=("GET","POST"))