[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),
})

View File

@ -191,7 +191,7 @@ header.navbar { display: none !important; }
{% for cd in calendar_days %}
<div class="day-cell{% if cd.is_today %} day-cell--today{% endif %}"
style="background:{% if not cd.is_today %}{{ cd.color }}{% endif %};">
<div class="day-number">{{ cd.day }}</div>
<div class="day-number"><a href="{% url 'vrobbler-home' %}?date={{ year }}-{{ month|stringformat:'02d' }}-{{ cd.day|stringformat:'02d' }}" style="color:inherit;text-decoration:none;">{{ cd.day }}</a>{% if cd.total_count > 0 %} <span style="font-weight:400;color:#999;font-size:0.75rem;">{{ cd.total_count }}</span>{% endif %}</div>
{% for s in cd.scrobbles %}
<a href="{% url 'scrobbles:detail' uuid=s.uuid %}"
class="event-card"