update dashboard + dashboard helpers

also untested
This commit is contained in:
Lili (Tlapka) 2022-10-12 15:48:57 +02:00
parent 5384076f64
commit 3c5a09b2de
3 changed files with 26 additions and 9 deletions

View File

@ -141,6 +141,15 @@ def clear_redeem_queue(db):
except Error as e: except Error as e:
print("Error occured deleting redeem queue:", e.args[0]) print("Error occured deleting redeem queue:", e.args[0])
def all_counters(db):
try:
cursor = db.execute(
"""SELECT counters.name, counters.count FROM counters"""
)
return cursor.fetchall()
except Error as e:
print("Error occured selecting all counters:", e.args[0])
def pretty_redeem_queue(db): def pretty_redeem_queue(db):
try: try:
cursor = db.execute( cursor = db.execute(

View File

@ -7,14 +7,11 @@ bp = Blueprint('redeem_dashboard', __name__)
@bp.route('/dashboard',methods=['GET']) @bp.route('/dashboard',methods=['GET'])
def dashboard(): def dashboard():
queue = pretty_redeem_queue(get_db()) db = get_db()
number_of_drinks = 0 queue = pretty_redeem_queue(db)
counters = all_counters(db)
utc_timezone = timezone.utc utc_timezone = timezone.utc
if queue is not None:
for row in queue:
if row[1] == "drink":
number_of_drinks += 1
return render_template('dashboard.html', return render_template('dashboard.html',
queue=queue, queue=queue,
number_of_drinks=number_of_drinks, counters=counters,
utc_timezone=utc_timezone) utc_timezone=utc_timezone)

View File

@ -5,12 +5,21 @@
<title>Redeems Dashboard</title> <title>Redeems Dashboard</title>
</head> </head>
<body> <body>
{% if counters %}
<table> <table>
<thead>
<tr>
<th>Counters</th>
</tr>
</thead>
<tbody> <tbody>
<td> Number of drinks: </td> {% for counter in counters %}
<td> {{ number_of_drinks }} </td> <td> {{ counter[0] }} </td>
<td> {{ counter[1] }} </td>
</tbody> </tbody>
</table> </table>
{% endif %}
{% if queue %} {% if queue %}
<table> <table>
<thead> <thead>
@ -18,6 +27,7 @@
<th>time</th> <th>time</th>
<th>redeem</th> <th>redeem</th>
<th>redeemer</th> <th>redeemer</th>
<th>note</th>
</tr> </tr>
</thead> </thead>
{% for row in queue %} {% for row in queue %}
@ -25,6 +35,7 @@
<td>{{ row[0].replace(tzinfo=utc_timezone).astimezone().strftime("%H:%M") }}</td> <td>{{ row[0].replace(tzinfo=utc_timezone).astimezone().strftime("%H:%M") }}</td>
<td>{{ row[1] }}</td> <td>{{ row[1] }}</td>
<td>{{ row[2] }}</td> <td>{{ row[2] }}</td>
<td>{{ row[3] }}</td>
</tbody> </tbody>
{% endfor %} {% endfor %}
</table> </table>