From 2cf2050dac2b9582e01b30a28d41f2056bf23d67 Mon Sep 17 00:00:00 2001 From: Lili Date: Thu, 20 Oct 2022 16:10:28 +0200 Subject: [PATCH] dashboard wrong points workaround dashboard now shows the points of every user with same username --- tlapbot/owncast_helpers.py | 12 ++++-------- tlapbot/owncast_redeem_dashboard.py | 8 ++++---- tlapbot/templates/dashboard.html | 10 ++++++---- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/tlapbot/owncast_helpers.py b/tlapbot/owncast_helpers.py index dc2ee1f..f7c57a8 100644 --- a/tlapbot/owncast_helpers.py +++ b/tlapbot/owncast_helpers.py @@ -46,18 +46,14 @@ def read_users_points(db, user_id): print("To user:", user_id) -def read_users_points_from_username(db, username): - """Returns None if user doesn't exist, their points otherwise.""" +def read_all_users_with_username(db, username): try: cursor = db.execute( - "SELECT points FROM points WHERE name = ?", + "SELECT name, points FROM points WHERE name = ?", (username,) ) - points = cursor.fetchone() - if points is None: - return None - else: - return points[0] + users = cursor.fetchall() + return users except Error as e: print("Error occured reading points from username:", e.args[0]) print("To user:", username) diff --git a/tlapbot/owncast_redeem_dashboard.py b/tlapbot/owncast_redeem_dashboard.py index db71a79..263f301 100644 --- a/tlapbot/owncast_redeem_dashboard.py +++ b/tlapbot/owncast_redeem_dashboard.py @@ -1,7 +1,7 @@ from flask import render_template, Blueprint, request from tlapbot.db import get_db 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 bp = Blueprint('redeem_dashboard', __name__) @@ -14,13 +14,13 @@ def dashboard(): counters = all_counters(db) username = request.args.get("username") if username is not None: - user_points = read_users_points_from_username(db, username) + users = read_all_users_with_username(db, username) else: - user_points = None + users = [] utc_timezone = timezone.utc return render_template('dashboard.html', queue=queue, counters=counters, username=username, - user_points=user_points, + users=users, utc_timezone=utc_timezone) diff --git a/tlapbot/templates/dashboard.html b/tlapbot/templates/dashboard.html index b6814b1..bebbc1d 100644 --- a/tlapbot/templates/dashboard.html +++ b/tlapbot/templates/dashboard.html @@ -5,17 +5,19 @@ Redeems Dashboard - {% if (username and user_points ) %} + {% if (username and users ) %} - + + {% for user in users %} - - + + + {% endfor %}
Your points balance:Points balance:
{{ username }} {{ user_points }} {{ user[0] }} {{ user[1] }}
{% endif %}