Now shows profile picture on profile page, and doesn't overwrite with nothing if you don't send in a file when saving settings
This commit is contained in:
parent
ea2f3f84e5
commit
33ebdcaceb
3 changed files with 13 additions and 8 deletions
17
Tweeder.py
17
Tweeder.py
|
@ -131,17 +131,22 @@ def user_settings():
|
|||
print(request.form)
|
||||
if 'username' not in session.keys():
|
||||
return redirect(url_for('login'))
|
||||
profile = {
|
||||
updated_profile = {
|
||||
'bio': request.form['bio'],
|
||||
'gender': request.form['gender'],
|
||||
'location': request.form['location']
|
||||
}
|
||||
if 'profile-pic' in request.files.keys():
|
||||
profile_pic = files.upload_file(request.files['profile_pic'])
|
||||
profile['profile_pic'] = profile_pic
|
||||
if 'profile_pic' in request.files.keys():
|
||||
if request.files['profile_pic'].filename == '':
|
||||
if accounts.account_details(session['username'].lower())['profile']['profile_pic']:
|
||||
profile_pic = accounts.account_details(session['username'].lower())['profile']['profile_pic']
|
||||
updated_profile['profile_pic'] = profile_pic
|
||||
else:
|
||||
profile_pic = files.upload_file(request.files['profile_pic'])
|
||||
updated_profile['profile_pic'] = profile_pic
|
||||
accounts.set_theme(session['username'].lower(), request.form['theme'])
|
||||
username = session['username']
|
||||
accounts.update_profile(username, profile)
|
||||
accounts.update_profile(username, updated_profile)
|
||||
return redirect(request.referrer)
|
||||
|
||||
|
||||
|
@ -225,7 +230,7 @@ def unlike_post(post_id):
|
|||
@app.route("/files/<oid>", methods=['GET'])
|
||||
def get_file(oid):
|
||||
fl = files.get_file(oid)
|
||||
if not fl: return "File not found"
|
||||
if not fl: return abort(404)
|
||||
response = make_response(fl.read())
|
||||
response.mimetype = fl.content_type
|
||||
return response
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<div class="container">
|
||||
<div class="jumbotron">
|
||||
{% if user.profile.profile_pic %}
|
||||
<img src="/files/{{ user.profile.profile_pic }}" class="rounded-circle float-left" style="margin-right: 24px; max-height: 100px;"/>
|
||||
<img src="/files/{{ user.profile.profile_pic }}" class="rounded float-left" style="margin-right: 24px; max-height: 100px;"/>
|
||||
{% endif %}
|
||||
<h1>{% if user.verified %} <i class="fas fa-shield-check" alt="Verified"></i> {% endif %}{{ user.displayname }} <small>on Tweeder</small></h1>
|
||||
<h2>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<form method="POST" action="/settings" class="col-lg-6" enctype="multipart/form-data">
|
||||
<div class="form-group row">
|
||||
<h2>Profile Picture</h2>
|
||||
<input type="file" name="profile-pic" size="40">
|
||||
<input type="file" name="profile_pic" size="40">
|
||||
<h2>Profile Fields</h2>
|
||||
|
||||
<div class="input-group mb-3">
|
||||
|
|
Loading…
Add table
Reference in a new issue