From: Chris Fulljames Date: Fri, 10 Jan 2025 01:37:22 +0000 (-0500) Subject: Add user bio X-Git-Url: https://littlesong.place/gitweb/?a=commitdiff_plain;h=31bf2e728190a6bdc5017b61339495ed3d9e9439;p=littlesongplace.git Add user bio --- diff --git a/main.py b/main.py index 77611ad..e56bebd 100644 --- a/main.py +++ b/main.py @@ -113,14 +113,26 @@ def users_profile(profile_username): # Get songs for current profile profile_userid = profile_data["userid"] + profile_bio = profile_data["bio"] songs = Song.get_all_for_user(profile_userid) return render_template( "profile.html", name=profile_username, userid=profile_userid, + bio=profile_bio, song_list=render_template("song-list.html", songs=songs)) +@app.post("/update-bio") +def update_bio(): + query_db( + "update users set bio = ? where userid = ?", + [request.form["bio"], session["userid"]]) + get_db().commit() + flash("Bio updated successfully") + + return redirect(f"/users/{session['username']}") + @app.get("/edit-song") def edit_song(): if not "userid" in session: diff --git a/schema.sql b/schema.sql index 2dcc41d..006709e 100644 --- a/schema.sql +++ b/schema.sql @@ -2,8 +2,10 @@ DROP TABLE IF EXISTS users; CREATE TABLE users ( userid INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT UNIQUE NOT NULL, - password TEXT NOT NULL + password TEXT NOT NULL, + bio TEXT ); +CREATE INDEX users_by_name ON users(username); DROP TABLE IF EXISTS songs; CREATE TABLE songs ( diff --git a/templates/profile.html b/templates/profile.html index f439d34..4cd2ff7 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -6,6 +6,40 @@

{{ name }}

+ +
{{ bio }}
+ + +{% if session["userid"] == userid %} + +Edit Bio + + + + + + +{% endif %} +

Songs

@@ -13,6 +47,7 @@ Upload New Song {% endif %} + {{ song_list|safe }} {% endblock %} diff --git a/todo.txt b/todo.txt index 4bbcb80..230c9a8 100644 --- a/todo.txt +++ b/todo.txt @@ -1,5 +1,4 @@ -- user bio -- edit user bio +- markup in user bio - delete user account - sort songs by upload timestamp