dashboard wrong points workaround

dashboard now shows the points of every user with same username
This commit is contained in:
Lili (Tlapka) 2022-10-20 16:10:28 +02:00
parent f0077c56dc
commit 2cf2050dac
3 changed files with 14 additions and 16 deletions

View File

@ -46,18 +46,14 @@ def read_users_points(db, user_id):
print("To user:", user_id) print("To user:", user_id)
def read_users_points_from_username(db, username): def read_all_users_with_username(db, username):
"""Returns None if user doesn't exist, their points otherwise."""
try: try:
cursor = db.execute( cursor = db.execute(
"SELECT points FROM points WHERE name = ?", "SELECT name, points FROM points WHERE name = ?",
(username,) (username,)
) )
points = cursor.fetchone() users = cursor.fetchall()
if points is None: return users
return None
else:
return points[0]
except Error as e: except Error as e:
print("Error occured reading points from username:", e.args[0]) print("Error occured reading points from username:", e.args[0])
print("To user:", username) print("To user:", username)

View File

@ -1,7 +1,7 @@
from flask import render_template, Blueprint, request from flask import render_template, Blueprint, request
from tlapbot.db import get_db from tlapbot.db import get_db
from tlapbot.owncast_helpers import (pretty_redeem_queue, all_counters, from tlapbot.owncast_helpers import (pretty_redeem_queue, all_counters,
read_users_points_from_username) read_all_users_with_username)
from datetime import datetime, timezone from datetime import datetime, timezone
bp = Blueprint('redeem_dashboard', __name__) bp = Blueprint('redeem_dashboard', __name__)
@ -14,13 +14,13 @@ def dashboard():
counters = all_counters(db) counters = all_counters(db)
username = request.args.get("username") username = request.args.get("username")
if username is not None: if username is not None:
user_points = read_users_points_from_username(db, username) users = read_all_users_with_username(db, username)
else: else:
user_points = None users = []
utc_timezone = timezone.utc utc_timezone = timezone.utc
return render_template('dashboard.html', return render_template('dashboard.html',
queue=queue, queue=queue,
counters=counters, counters=counters,
username=username, username=username,
user_points=user_points, users=users,
utc_timezone=utc_timezone) utc_timezone=utc_timezone)

View File

@ -5,17 +5,19 @@
<title>Redeems Dashboard</title> <title>Redeems Dashboard</title>
</head> </head>
<body> <body>
{% if (username and user_points ) %} {% if (username and users ) %}
<table> <table>
<thead> <thead>
<tr> <tr>
<th>Your points balance:</th> <th>Points balance:</th>
</tr> </tr>
</thead> </thead>
{% for user in users %}
<tbody> <tbody>
<td> {{ username }} </td> <td> {{ user[0] }} </td>
<td> {{ user_points }} </td> <td> {{ user[1] }} </td>
</tbody> </tbody>
{% endfor %}
</table> </table>
{% endif %} {% endif %}