Improve month calendar
This commit is contained in:
@@ -156,6 +156,35 @@ def dashboard():
|
||||
badges.append("Night Owl: Logged Readings Every Night for a Week")
|
||||
|
||||
return badges
|
||||
|
||||
def generate_monthly_calendar(readings, selected_date, local_timezone):
|
||||
# Convert selected date to user's timezone and extract the start/end dates
|
||||
today = datetime.now(local_timezone).date()
|
||||
date = selected_date.astimezone(local_timezone).date()
|
||||
first_day_of_month = date.replace(day=1)
|
||||
days_to_subtract = (first_day_of_month.weekday() + 1) % 7
|
||||
start_date = first_day_of_month - timedelta(days=days_to_subtract)
|
||||
end_date = start_date + timedelta(days=6 * 7 - 1)
|
||||
|
||||
# Group readings by day
|
||||
readings_by_day = {}
|
||||
for reading in readings:
|
||||
local_date = reading.timestamp.astimezone(local_timezone).date()
|
||||
readings_by_day.setdefault(local_date, []).append(reading)
|
||||
|
||||
# Build calendar days
|
||||
calendar = []
|
||||
current_date = start_date
|
||||
while current_date <= end_date:
|
||||
calendar.append({
|
||||
'day': current_date.day,
|
||||
'is_today': current_date == today,
|
||||
'is_in_current_month': current_date.month == date.month,
|
||||
'readings': readings_by_day.get(current_date, []),
|
||||
})
|
||||
current_date += timedelta(days=1)
|
||||
|
||||
return calendar
|
||||
|
||||
# Get the first and last reading timestamps
|
||||
first_reading_timestamp, last_reading_timestamp = get_reading_date_range(current_user.id)
|
||||
@@ -188,6 +217,8 @@ def dashboard():
|
||||
reading.relative_timestamp = humanize.naturaltime(now - reading.timestamp)
|
||||
reading.local_timestamp = utc.localize(reading.timestamp).astimezone(local_tz)
|
||||
|
||||
month_view = generate_monthly_calendar(readings, now, local_tz)
|
||||
|
||||
# Calculate weekly summary and progress badges
|
||||
systolic_avg, diastolic_avg, heart_rate_avg = calculate_weekly_summary(readings)
|
||||
badges = calculate_progress_badges(readings)
|
||||
@@ -223,6 +254,7 @@ def dashboard():
|
||||
start_date=start_date,
|
||||
end_date=end_date,
|
||||
readings_by_date=readings_by_date,
|
||||
month = month_view,
|
||||
date=date,
|
||||
timedelta=timedelta
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user