[calendar] Add fun to calendar day links
This commit is contained in:
@ -1368,6 +1368,20 @@ class ScrobbleCalendarView(LoginRequiredMixin, TemplateView):
|
|||||||
.order_by("timestamp")
|
.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)}
|
day_map = {d: [] for d in range(1, total_days + 1)}
|
||||||
for scrobble in scrobbles:
|
for scrobble in scrobbles:
|
||||||
local_ts = timezone.localtime(scrobble.timestamp)
|
local_ts = timezone.localtime(scrobble.timestamp)
|
||||||
@ -1395,6 +1409,7 @@ class ScrobbleCalendarView(LoginRequiredMixin, TemplateView):
|
|||||||
calendar_days.append({
|
calendar_days.append({
|
||||||
"day": day_num,
|
"day": day_num,
|
||||||
"scrobbles": day_scrobbles,
|
"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,
|
"is_today": year == today.year and month == today.month and day_num == today.day,
|
||||||
"color": self._day_color(month, day_num, total_days),
|
"color": self._day_color(month, day_num, total_days),
|
||||||
})
|
})
|
||||||
|
|||||||
@ -191,7 +191,7 @@ header.navbar { display: none !important; }
|
|||||||
{% for cd in calendar_days %}
|
{% for cd in calendar_days %}
|
||||||
<div class="day-cell{% if cd.is_today %} day-cell--today{% endif %}"
|
<div class="day-cell{% if cd.is_today %} day-cell--today{% endif %}"
|
||||||
style="background:{% if not cd.is_today %}{{ cd.color }}{% 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 %}
|
{% for s in cd.scrobbles %}
|
||||||
<a href="{% url 'scrobbles:detail' uuid=s.uuid %}"
|
<a href="{% url 'scrobbles:detail' uuid=s.uuid %}"
|
||||||
class="event-card"
|
class="event-card"
|
||||||
|
|||||||
Reference in New Issue
Block a user