add total truescore and total patrons to poll_votes.html

pull/66/head
Aevann1 2022-12-14 19:28:31 +02:00
parent b176bc79ac
commit ac4a2c8ff7
2 changed files with 33 additions and 2 deletions

View File

@ -63,10 +63,22 @@ def option_votes(option_id, v):
if option.post.ghost: abort(403)
ups = g.db.query(SubmissionOptionVote).filter_by(option_id=option_id).order_by(SubmissionOptionVote.created_utc).all()
user_ids = [x[0] for x in g.db.query(SubmissionOptionVote.user_id).filter_by(option_id=option_id).all()]
total_ts = g.db.query(func.sum(User.truescore)).filter(User.id.in_(user_ids)).scalar()
total_ts = format(total_ts, ",") if total_ts else '0'
if v.admin_level >= 3:
total_patrons = g.db.query(User).filter(User.id.in_(user_ids), User.patron > 0).count()
else:
total_patrons = None
return render_template("poll_votes.html",
v=v,
thing=option,
ups=ups)
ups=ups,
total_ts=total_ts,
total_patrons=total_patrons,
)
@ -119,7 +131,19 @@ def option_votes_comment(option_id, v):
ups = g.db.query(CommentOptionVote).filter_by(option_id=option_id).order_by(CommentOptionVote.created_utc).all()
user_ids = [x[0] for x in g.db.query(CommentOptionVote.user_id).filter_by(option_id=option_id).all()]
total_ts = g.db.query(func.sum(User.truescore)).filter(User.id.in_(user_ids)).scalar()
total_ts = format(total_ts, ",") if total_ts else '0'
if v.admin_level >= 3:
total_patrons = g.db.query(User).filter(User.id.in_(user_ids), User.patron > 0).count()
else:
total_patrons = None
return render_template("poll_votes.html",
v=v,
thing=option,
ups=ups)
ups=ups,
total_ts=total_ts,
total_patrons=total_patrons,
)

View File

@ -2,7 +2,14 @@
{% block pagetitle %}Poll Votes{% endblock %}
{% block content %}
{% if thing %}
<h3 class="mt-5">{{thing.body_html | safe}} - {{ups | length}} {% if thing.exclusive == 2 %}bets{% else %}votes{% endif %}</h3>
<p class="mt-4"><b>Total voter truescore: </b>{{total_ts}}</p>
{% if total_patrons %}
<p><b>Total patrons: </b>{{total_patrons}}</p>
{% endif %}
<div class="overflow-x-auto mt-5">
<table class="table table-striped mb-5">
<thead class="bg-primary text-white">