Change readings table to list of cards, also update edit reading page to include link to delete reading

This commit is contained in:
Peter Stockings
2024-12-26 16:06:55 +11:00
parent 26cf035b22
commit 97a8e54e11
5 changed files with 201 additions and 69 deletions

View File

@@ -2,6 +2,7 @@ import csv
from io import StringIO
import io
from flask import Blueprint, Response, make_response, render_template, redirect, request, send_file, url_for, flash
import humanize
from sqlalchemy import func
from werkzeug.security import generate_password_hash, check_password_hash
from werkzeug.http import http_date
@@ -104,6 +105,12 @@ def dashboard():
# Fetch and order readings
readings = readings_query.order_by(Reading.timestamp.desc()).all()
# Add human-readable relative timestamps to readings
now = datetime.utcnow()
for reading in readings:
reading.relative_timestamp = humanize.naturaltime(now - reading.timestamp)
# Weekly summary (last 7 days)
one_week_ago = datetime.now() - timedelta(days=7)
weekly_readings = [r for r in readings if r.timestamp >= one_week_ago]