summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorubq323 <ubq323>2021-06-28 23:48:33 +0000
committerubq323 <ubq323>2021-06-28 23:48:33 +0000
commitedbd48340de9add59bcf34f312ae036adae8dcfd (patch)
tree53241bc56c1fd689d841abad73208c14ede30354
parentcd8b3aa2c5abd414068c8f9f5edbebab807153eb (diff)
displayation of vote retractions
-rw-r--r--apioforum/db.py4
-rw-r--r--apioforum/templates/view_thread.html30
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 %}
</div>
{% if g.user %}