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:
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):
try:
cursor = db.execute(

View File

@ -7,14 +7,11 @@ bp = Blueprint('redeem_dashboard', __name__)
@bp.route('/dashboard',methods=['GET'])
def dashboard():
queue = pretty_redeem_queue(get_db())
number_of_drinks = 0
db = get_db()
queue = pretty_redeem_queue(db)
counters = all_counters(db)
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',
queue=queue,
number_of_drinks=number_of_drinks,
counters=counters,
utc_timezone=utc_timezone)

View File

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