From: Chris Fulljames Date: Thu, 9 Jan 2025 12:20:30 +0000 (-0500) Subject: Refactor duplicated song list HTML X-Git-Url: https://littlesong.place/gitweb/gitweb.cgi?a=commitdiff_plain;h=43876f665decd6b67ddb94256ef0bf5e4b30483a;p=littlesongplace.git Refactor duplicated song list HTML --- diff --git a/main.py b/main.py index 5792552..2438100 100644 --- a/main.py +++ b/main.py @@ -119,7 +119,7 @@ def users_profile(profile_username): "profile.html", name=profile_username, userid=profile_userid, - songs=songs) + song_list=render_template("song-list.html", songs=songs)) @app.get("/edit-song") def edit_song(): diff --git a/templates/profile.html b/templates/profile.html index 4e02997..f439d34 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -13,48 +13,7 @@ Upload New Song {% endif %} - - -{% for song in songs %} -
- -

{{ song.title }}

- - - {% if session["userid"] == userid %} -
- Edit -
-
- Delete -
- {% endif %} - - - - - -
{{ song.description }}
- - -
- {% for tag in song.tags %} - {{ tag }} - {% endfor %} -
- - -
- {% for collab in song.collaborators %} - {% if collab.startswith("@") %} - {{ collab }} - {% else %} - {{ collab }} - {% endif %} - {% endfor %} -
-
-{% endfor %} +{{ song_list|safe }} {% endblock %} diff --git a/templates/song-list.html b/templates/song-list.html new file mode 100644 index 0000000..1ee7d80 --- /dev/null +++ b/templates/song-list.html @@ -0,0 +1,40 @@ +{% for song in songs %} +
+ +

{{ song.title }}

+ + + {% if session["userid"] == song.userid %} +
+ Edit +
+
+ Delete +
+ {% endif %} + + + + + +
{{ song.description }}
+ + +
+ {% for tag in song.tags %} + {{ tag }} + {% endfor %} +
+ + +
+ {% for collab in song.collaborators %} + {% if collab.startswith("@") %} + {{ collab }} + {% else %} + {{ collab }} + {% endif %} + {% endfor %} +
+
+{% endfor %} diff --git a/templates/songs-by-tag.html b/templates/songs-by-tag.html index 7d67edb..341de24 100644 --- a/templates/songs-by-tag.html +++ b/templates/songs-by-tag.html @@ -6,45 +6,6 @@

Songs tagged with '{{ tag }}'

-{% for song in songs %} -
- -

{{ song.title }}

- - - {% if session["userid"] == userid %} -
- Edit -
-
- Delete -
- {% endif %} - - - - - -
{{ song.description }}
- - -
- {% for tag in song.tags %} - {{ tag }} - {% endfor %} -
- - -
- {% for collab in song.collaborators %} - {% if collab.startswith("@") %} - {{ collab }} - {% else %} - {{ collab }} - {% endif %} - {% endfor %} -
-
-{% endfor %} +{{ song_list|safe }} {% endblock %} diff --git a/todo.txt b/todo.txt index 996604f..4bbcb80 100644 --- a/todo.txt +++ b/todo.txt @@ -3,6 +3,8 @@ - delete user account - sort songs by upload timestamp +- automated tests + - javascript song player - admin account(s)