When filtering readings on dashboard show selected start/end date and show filter accordion by default
This commit is contained in:
@@ -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'])
|
||||
|
||||
Reference in New Issue
Block a user