From 1ca8b3a4a8d4eac3a43aadb4d00fbc1973d05cc3 Mon Sep 17 00:00:00 2001 From: Chris Fulljames Date: Tue, 4 Feb 2025 07:22:34 -0500 Subject: [PATCH] Add PFPs --- .gitignore | 1 + main.py | 30 ++++++++++++++++++++++++------ static/styles.css | 21 ++++++++++++++++++++- templates/profile.html | 25 ++++++++++++++++++++----- test/lsp_notes.png | Bin 0 -> 214 bytes test/test_offline.py | 31 ++++++++++++++++++++++++++++++- todo.txt | 4 ++-- 7 files changed, 97 insertions(+), 15 deletions(-) create mode 100644 test/lsp_notes.png diff --git a/.gitignore b/.gitignore index b9030d3..1543466 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,6 @@ venv __pycache__ database.db songs +images app.log* diff --git a/main.py b/main.py index a8ff878..a3497a6 100644 --- a/main.py +++ b/main.py @@ -165,18 +165,30 @@ def users_profile(profile_username): bio=profile_bio, song_list=render_template("song-list.html", songs=songs)) -@app.post("/update-bio") -def update_bio(): +@app.post("/edit-profile") +def edit_profile(): + if not "userid" in session: + abort(401) + query_db( "update users set bio = ? where userid = ?", [request.form["bio"], session["userid"]]) get_db().commit() - flash("Bio updated successfully") + + if request.files["pfp"]: + pfp_path = get_user_images_path(session["userid"]) / "pfp" + request.files["pfp"].save(pfp_path) + + flash("Profile updated successfully") app.logger.info(f"{session['username']} updated bio") return redirect(f"/users/{session['username']}") +@app.get("/pfp/") +def pfp(userid): + return send_from_directory(DATA_DIR / "images" / str(userid), "pfp") + @app.get("/edit-song") def edit_song(): if not "userid" in session: @@ -267,12 +279,18 @@ def validate_song_form(): return error -def get_user_path(userid): +def get_user_songs_path(userid): userpath = DATA_DIR / "songs" / str(userid) if not userpath.exists(): os.makedirs(userpath) return userpath +def get_user_images_path(userid): + userpath = DATA_DIR / "images" / str(userid) + if not userpath.exists(): + os.makedirs(userpath) + return userpath + def update_song(): songid = request.args["songid"] try: @@ -300,7 +318,7 @@ def update_song(): if passed: # Move file to permanent location - filepath = get_user_path(session["userid"]) / (str(song_data["songid"]) + ".mp3") + filepath = get_user_songs_path(session["userid"]) / (str(song_data["songid"]) + ".mp3") shutil.move(tmp_file.name, filepath) else: error = True @@ -345,7 +363,7 @@ def create_song(): "insert into songs (userid, title, description, created) values (?, ?, ?, ?) returning (songid)", [session["userid"], title, description, timestamp], one=True) songid = song_data["songid"] - filepath = get_user_path(session["userid"]) / (str(song_data["songid"]) + ".mp3") + filepath = get_user_songs_path(session["userid"]) / (str(song_data["songid"]) + ".mp3") # Move file to permanent location shutil.move(tmp_file.name, filepath) diff --git a/static/styles.css b/static/styles.css index 3500ea4..3cb63a3 100644 --- a/static/styles.css +++ b/static/styles.css @@ -59,6 +59,7 @@ input[type=text], input[type=password] { font-family: sans-serif; font-size: 16px; font-weight: bold; + text-decoration: none; color: var(--yellow); background: var(--purple); border: 0px; @@ -165,8 +166,26 @@ input[type=file] { font-size: 40px; } +.big-pfp-container { + margin: 0 auto; + width: 200px; + max-width: 80%; + background: var(--purple); + padding: 5px; + border-radius: 10px; +} + +.big-pfp { + width: 100%; + max-height: 200px; + margin: 0px; + padding: 0px; + display: block; + border-radius: 5px; +} + .profile-action { - margin: 10px; + margin-bottom: 20px; } .profile-edit-buttons { diff --git a/templates/profile.html b/templates/profile.html index 3f8bcee..308cb69 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -4,19 +4,34 @@ {% block body %} +

{{ name }}

+ +
+ +
+ + +
{{ (bio.replace("\n", "
"))|safe }}
- + {% if session["userid"] == userid %}
- Edit Bio +
- - +