[calendar] Add fun to calendar day links
This commit is contained in:
@ -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),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user