diff --git a/app/routes.py b/app/routes.py index 78dc2d4..5c562c5 100644 --- a/app/routes.py +++ b/app/routes.py @@ -47,6 +47,10 @@ def logout(): def dashboard(): from datetime import datetime, timedelta + # Default values + start_date = None + end_date = None + # Default to all readings readings_query = Reading.query.filter_by(user_id=current_user.id) @@ -56,13 +60,17 @@ def dashboard(): end_date = request.form.get('end_date') if start_date and end_date: - start_date = datetime.strptime(start_date, '%Y-%m-%d') - end_date = datetime.strptime(end_date, '%Y-%m-%d') + start_date_obj = datetime.strptime(start_date, '%Y-%m-%d') + end_date_obj = datetime.strptime(end_date, '%Y-%m-%d') readings_query = readings_query.filter( - Reading.timestamp >= start_date, - Reading.timestamp <= end_date + Reading.timestamp >= start_date_obj, + Reading.timestamp <= end_date_obj ) + # Format start_date and end_date for the template + start_date = start_date_obj.strftime('%Y-%m-%d') + end_date = end_date_obj.strftime('%Y-%m-%d') + # Fetch and order readings readings = readings_query.order_by(Reading.timestamp.desc()).all() @@ -103,7 +111,9 @@ def dashboard(): timestamps=timestamps, systolic=systolic, diastolic=diastolic, - heart_rate=heart_rate + heart_rate=heart_rate, + start_date=start_date, + end_date=end_date ) @main.route('/add-reading', methods=['GET', 'POST']) diff --git a/app/templates/dashboard.html b/app/templates/dashboard.html index 3ac410f..45b499e 100644 --- a/app/templates/dashboard.html +++ b/app/templates/dashboard.html @@ -125,7 +125,8 @@ -
+

Filter Readings

@@ -146,12 +147,12 @@
-
-