[calendar] Add fun to calendar day links
Some checks failed
build & deploy / test (push) Successful in 1m52s
build & deploy / build-and-deploy (push) Has been cancelled

This commit is contained in:
2026-05-27 14:10:37 -04:00
parent b4e15c73c1
commit 25baeca2b0
2 changed files with 16 additions and 1 deletions

View File

@ -1368,6 +1368,20 @@ class ScrobbleCalendarView(LoginRequiredMixin, TemplateView):
.order_by("timestamp")
)
from django.db.models import Count
from django.db.models.functions import TruncDate
total_by_day = dict(
Scrobble.objects.filter(
user=self.request.user,
timestamp__date__gte=month_start,
timestamp__date__lte=month_end,
)
.annotate(local_date=TruncDate("timestamp", tzinfo=timezone.get_current_timezone()))
.values("local_date")
.annotate(count=Count("id"))
.values_list("local_date", "count")
)
day_map = {d: [] for d in range(1, total_days + 1)}
for scrobble in scrobbles:
local_ts = timezone.localtime(scrobble.timestamp)
@ -1395,6 +1409,7 @@ class ScrobbleCalendarView(LoginRequiredMixin, TemplateView):
calendar_days.append({
"day": day_num,
"scrobbles": day_scrobbles,
"total_count": total_by_day.get(datetime(year, month, day_num).date(), 0),
"is_today": year == today.year and month == today.month and day_num == today.day,
"color": self._day_color(month, day_num, total_days),
})