]> littlesong.place Git - littlesongplace.git/commitdiff
Add random songs to homepage
authorChris Fulljames <christianfulljames@gmail.com>
Sat, 9 Aug 2025 18:26:17 +0000 (14:26 -0400)
committerChris Fulljames <christianfulljames@gmail.com>
Sat, 9 Aug 2025 18:26:17 +0000 (14:26 -0400)
src/littlesongplace/__init__.py
src/littlesongplace/templates/index.html
src/littlesongplace/templates/news.html
test/test_songlists.py

index 5ebb6227c9e401ea533bdcc6460a16bbe9a7b5f9..a13d13a27868ccc674659e1b3a676a4bf43ba149 100644 (file)
@@ -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,
index 5b7a662eab52342b72be153000c1f27fff324562..78d41b3a46f496890885a91fe972e91d840d7ceb 100644 (file)
     {% endfor %}
 </div>
 
-<h2>hot new tunes</h2>
 {%- from "song-macros.html" import song_list %}
+<h2>human music</h2>
+
+{{ song_list(random_songs, current_user_playlists) }}
+
+<h2>hot new tunes</h2>
 
 {%- for songs in songs_by_user %}
 <div class="upload-block">
index 68553dad7ee713526874e1b79cd8ffb91d78bb04..2b9424bc78179690ddcf3d7ceb5686650c540e25 100644 (file)
@@ -5,6 +5,10 @@
 {% block body %}
 
 <h1>site news</h1>
+<h2>2025-07-24 - Random Homepage Songs</h2>
+<p>
+The homepage now shows a few random songs before the hot new tunes.
+</p>
 
 <h2>2025-07-24 - Server Updates</h2>
 <p>
index 1bfd84a53a1371849452a5ae7f311684640639bb..ada0a00bbef8172806530eb19205bee923166e8f 100644 (file)
@@ -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 #################################################################