From edbd48340de9add59bcf34f312ae036adae8dcfd Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 28 Jun 2021 23:48:33 +0000 Subject: displayation of vote retractions --- apioforum/db.py | 4 +++- apioforum/templates/view_thread.html | 30 ++++++++++++++++++------------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/apioforum/db.py b/apioforum/db.py index 67989df..25bda94 100644 --- a/apioforum/db.py +++ b/apioforum/db.py @@ -102,9 +102,11 @@ CREATE TABLE votes ( id INTEGER PRIMARY KEY, user TEXT NOT NULL REFERENCES users(username), poll INTEGER NOT NULL, - option_idx INTEGER NOT NULL, + option_idx INTEGER, time TIMESTAMP NOT NULL, current INTEGER NOT NULL, + is_retraction INTEGER, + CHECK (is_retraction OR (option_idx NOT NULL)), FOREIGN KEY ( poll, option_idx ) REFERENCES poll_options(poll, option_idx) ); ALTER TABLE posts ADD COLUMN vote INTEGER REFERENCES votes(id); diff --git a/apioforum/templates/view_thread.html b/apioforum/templates/view_thread.html index 622cf06..b999658 100644 --- a/apioforum/templates/view_thread.html +++ b/apioforum/templates/view_thread.html @@ -33,21 +33,27 @@ {% 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 %} + {# this is bad but it's going to get refactored anyway #} + {% set footer %} + {% if vote.is_retraction %} + {{post.author}} retracted their vote + {% else %} + {% set option = poll.options[option_idx-1] %} + {% 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 %} + {% endif %} - {{ disp_post(post, buttons=True, footer=footer) }} - + {% endset %} + + {{ disp_post(post, buttons=True, footer=footer) }} + {% else %} - {{ disp_post(post, buttons=True) }} - {% endif %} + {{ disp_post(post, buttons=True) }} + {% endif %} {% endfor %} {% if g.user %} -- cgit v1.2.3