]> littlesong.place Git - littlesongplace.git/commitdiff
Add Random page
authorChris Fulljames <christianfulljames@gmail.com>
Wed, 26 Feb 2025 01:30:40 +0000 (20:30 -0500)
committerChris Fulljames <christianfulljames@gmail.com>
Wed, 26 Feb 2025 01:30:40 +0000 (20:30 -0500)
main.py
templates/base.html
todo.txt

diff --git a/main.py b/main.py
index b07eb0e76b5c33e63778617a01427d3e93f54115..200741053fee4bfbb7cee486ea42a309e7f7ce20 100644 (file)
--- a/main.py
+++ b/main.py
@@ -567,7 +567,7 @@ def songs():
     elif user:
         songs = Song.get_all_for_username(user)
     else:
-        songs = []
+        songs = Song.get_random(50)
 
     return render_template("songs-by-tag.html", user=user, tag=tag, songs=songs, **colors)
 
@@ -1088,6 +1088,12 @@ class Song:
     def get_latest(cls, count):
         return cls._from_db("select * from songs inner join users on songs.userid = users.userid order by songs.created desc limit ?", [count])
 
+    @classmethod
+    def get_random(cls, count):
+        songs = cls._from_db("select * from songs inner join users on songs.userid = users.userid where songid in (select songid from songs order by random() limit ?)", [count])
+        random.shuffle(songs)
+        return songs
+
     @classmethod
     def get_for_playlist(cls, playlistid):
         return cls._from_db("""\
index 18cfc932f21c3455650aa58346709a4a8d6245f9..667651afd0f92e1f4dc1a99c6986f60d3b337d1e 100644 (file)
@@ -27,6 +27,7 @@
             <!-- Navbar -->
             <div class="navbar">
                 <a href="/">Home</a>
+                <a href="/songs">Random</a>
                 <a href="/site-news">News</a>
 
                 <a href="/users/{{ session["username"] }}" class="nav-logged-in" id="my-profile" hidden>My Profile</a>
index 5999e8bad02b7417fdaac1b79b5453790169c1bb..c21b51b9e9abd00b3c0be0dbc6198ddf5d17d82b 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -1,8 +1,6 @@
 NOW
 - Pinned profile playlists
 - Player minimize button
-- Shuffle all page
-- Shuffle song list toggle
 - Loop song list toggle
 
 SOON