From: Chris Fulljames Date: Sat, 9 Aug 2025 18:26:17 +0000 (-0400) Subject: Add random songs to homepage X-Git-Url: https://littlesong.place/gitweb/?a=commitdiff_plain;h=f4b6247e20ccd631d754980ea8b471a1ef03c5eb;p=littlesongplace.git Add random songs to homepage --- diff --git a/src/littlesongplace/__init__.py b/src/littlesongplace/__init__.py index 5ebb622..a13d13a 100644 --- a/src/littlesongplace/__init__.py +++ b/src/littlesongplace/__init__.py @@ -79,6 +79,8 @@ def index(): ongoing_events, upcoming_events, _, _ = jams._sort_events(all_events) app.logger.info(f"Homepage jams in {time.perf_counter() - start} seconds") + random_songs = songs.get_random(3) + # Group songs by userid start = time.perf_counter() page_songs = songs.get_latest(100) @@ -96,6 +98,7 @@ def index(): page = render_template( "index.html", users=all_users, + random_songs=random_songs, songs_by_user=songs_by_user, page_title=title, ongoing_events=ongoing_events, diff --git a/src/littlesongplace/templates/index.html b/src/littlesongplace/templates/index.html index 5b7a662..78d41b3 100644 --- a/src/littlesongplace/templates/index.html +++ b/src/littlesongplace/templates/index.html @@ -32,8 +32,12 @@ {% endfor %} -

hot new tunes

{%- from "song-macros.html" import song_list %} +

human music

+ +{{ song_list(random_songs, current_user_playlists) }} + +

hot new tunes

{%- for songs in songs_by_user %}
diff --git a/src/littlesongplace/templates/news.html b/src/littlesongplace/templates/news.html index 68553da..2b9424b 100644 --- a/src/littlesongplace/templates/news.html +++ b/src/littlesongplace/templates/news.html @@ -5,6 +5,10 @@ {% block body %}

site news

+

2025-07-24 - Random Homepage Songs

+

+The homepage now shows a few random songs before the hot new tunes. +

2025-07-24 - Server Updates

diff --git a/test/test_songlists.py b/test/test_songlists.py index 1bfd84a..ada0a00 100644 --- a/test/test_songlists.py +++ b/test/test_songlists.py @@ -31,12 +31,12 @@ def test_homepage_songs_two_songs(client): songs = get_song_list_from_page(client, "/") # Newest first (all songs) - assert len(songs) == 2 - assert songs[0]["title"] == "song2" - assert songs[0]["username"] == "user2" + assert len(songs) == 4 # Includes random songs (both) + assert songs[2]["title"] == "song2" + assert songs[2]["username"] == "user2" - assert songs[1]["title"] == "song1" - assert songs[1]["username"] == "user1" + assert songs[3]["title"] == "song1" + assert songs[3]["username"] == "user1" # Songs by tag #################################################################