# 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:
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 (
<h1 class="profile-name">{{ name }}</h1>
+<!-- Bio -->
+<div class="profile-bio" id="profile-bio">{{ bio }}</div>
+
+<!-- Bio edit form -->
+{% if session["userid"] == userid %}
+
+<a href="javascript:showEditForm();" id="profile-bio-edit-btn">Edit Bio</a>
+
+<form id="profile-edit-form" action="/update-bio" method="post" hidden>
+ <div class="profile-edit">
+ <textarea name="bio">{{ bio }}</textarea>
+ </div>
+ <div class="profile-edit">
+ <a href="javascript:hideEditForm();">Cancel</a>
+ <input type="submit" value="Save">
+ </div>
+</form>
+
+<!-- Show/hide bio edit form -->
+<script>
+ function showEditForm() {
+ document.getElementById("profile-bio").hidden = true;
+ document.getElementById("profile-bio-edit-btn").hidden = true;
+ document.getElementById("profile-edit-form").hidden = false;
+ }
+ function hideEditForm() {
+ document.getElementById("profile-bio").hidden = false;
+ document.getElementById("profile-bio-edit-btn").hidden = false;
+ document.getElementById("profile-edit-form").hidden = true;
+ }
+</script>
+
+{% endif %}
+
<h2>Songs</h2>
<!-- Upload New Song button -->
<a href="/edit-song">Upload New Song</a>
{% endif %}
+<!-- Song List -->
{{ song_list|safe }}
{% endblock %}