[templates] Limit home scrobbles to 20 by default, configurable
All checks were successful
build & deploy / test (push) Successful in 2m18s
build & deploy / build-and-deploy (push) Successful in 36s

This commit is contained in:
2026-05-07 15:48:41 -04:00
parent 666224875b
commit a5510d7294
5 changed files with 53 additions and 4 deletions

View File

@ -34,6 +34,7 @@ class UserProfileForm(forms.ModelForm):
"redirect_to_webpage",
"enable_public_widgets",
"widget_custom_css",
"home_scrobble_limit",
]
widgets = {
"lastfm_password": forms.PasswordInput(render_value=True),

View File

@ -0,0 +1,18 @@
# Generated by Django 4.2.29 on 2026-05-07 19:26
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("profiles", "0030_userprofile_widget_custom_css"),
]
operations = [
migrations.AddField(
model_name="userprofile",
name="home_scrobble_limit",
field=models.IntegerField(default=20),
),
]

View File

@ -64,6 +64,8 @@ class UserProfile(TimeStampedModel):
enable_public_widgets = models.BooleanField(default=False)
widget_custom_css = models.TextField(**BNULL)
home_scrobble_limit = models.IntegerField(default=20)
def __str__(self):
return f"User profile for {self.user}"

View File

@ -212,6 +212,11 @@ class RecentScrobbleList(ListView):
self.queryset = self.get_queryset().filter(user=user)
user_id = self.request.user.id
# Get user's home scrobble limit (default 20)
home_limit = 20
if hasattr(user, 'profile') and user.profile.home_scrobble_limit:
home_limit = user.profile.home_scrobble_limit
today = timezone.localtime(timezone.now())
date_str = self.request.GET.get("date", "")
date = today
@ -228,9 +233,13 @@ class RecentScrobbleList(ListView):
data["next_link"] = f"?date={next_date.strftime('%Y-W%W')}"
data["prev_link"] = f"?date={prev_date.strftime('%Y-W%W')}"
data["title"] = f"Week {date.strftime('%-W')} of {date.year}"
data = data | Scrobble.as_dict_by_type(
scrobbles_dict = Scrobble.as_dict_by_type(
Scrobble.for_week(user_id, date.year, date.isocalendar()[1])
)
for key in list(scrobbles_dict.keys()):
if not key.endswith("_count") and not key.endswith("_time"):
scrobbles_dict[key] = scrobbles_dict[key][:home_limit]
data = data | scrobbles_dict
elif date_str == "this_month" or date_str.count("-") == 1:
next_date = date + relativedelta(months=1)
prev_date = date + relativedelta(months=-1)
@ -238,9 +247,13 @@ class RecentScrobbleList(ListView):
data["next_link"] = f"?date={next_date.strftime('%Y-%m')}"
data["title"] = f"{date.strftime('%B %Y')}"
data["prev_link"] = f"?date={prev_date.strftime('%Y-%m')}"
data = data | Scrobble.as_dict_by_type(
scrobbles_dict = Scrobble.as_dict_by_type(
Scrobble.for_month(user_id, date.year, date.month)
)
for key in list(scrobbles_dict.keys()):
if not key.endswith("_count") and not key.endswith("_time"):
scrobbles_dict[key] = scrobbles_dict[key][:home_limit]
data = data | scrobbles_dict
elif date_str == "today" or date_str.count("-") == 2:
next_date = date + timedelta(days=1)
prev_date = date - timedelta(days=1)
@ -264,18 +277,28 @@ class RecentScrobbleList(ListView):
data["next_link"] = f"?date={next_date.year}"
data["title"] = f"{date.year}"
data["prev_link"] = f"?date={prev_date.year}"
data = data | Scrobble.as_dict_by_type(
scrobbles_dict = Scrobble.as_dict_by_type(
Scrobble.for_year(user_id, date.year)
)
for key in list(scrobbles_dict.keys()):
if not key.endswith("_count") and not key.endswith("_time"):
scrobbles_dict[key] = scrobbles_dict[key][:home_limit]
data = data | scrobbles_dict
else:
next_date = today - timedelta(days=1)
prev_date = today - timedelta(days=1)
data["title"] = "Today"
data["next_link"] = ""
data["prev_link"] = f"?date={prev_date.strftime('%Y-%m-%d')}"
data = data | Scrobble.as_dict_by_type(
# Get scrobbles grouped by type, limit to 20 per type
scrobbles_dict = Scrobble.as_dict_by_type(
Scrobble.for_day(user_id, date.year, date.month, date.day)
)
# Limit each media type to 20 most recent
for key in list(scrobbles_dict.keys()):
if not key.endswith("_count") and not key.endswith("_time"):
scrobbles_dict[key] = scrobbles_dict[key][:20]
data = data | scrobbles_dict
data["today_link"] = "" # f"?date={today.strftime('%Y-%m-%d')}"
data["active_imports"] = AudioScrobblerTSVImport.objects.filter(

View File

@ -129,6 +129,11 @@
</ul>
</div>
{% endif %}
{% elif field.name == "home_scrobble_limit" %}
<p>
{{ field.label_tag }}
{{ field }}
</p>
{% else %}
<p>
{{ field.label_tag }}