From aef308e3fd46dcba780b7352f50133fd604d7135 Mon Sep 17 00:00:00 2001 From: kitoy Date: Sun, 7 Aug 2022 07:32:42 +0200 Subject: [PATCH] modified: templates/profil.html modified: views/profil.py --- templates/profil.html | 2 +- views/profil.py | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/templates/profil.html b/templates/profil.html index 2c115c0..9d55083 100644 --- a/templates/profil.html +++ b/templates/profil.html @@ -20,7 +20,7 @@

- +

diff --git a/views/profil.py b/views/profil.py index 9026697..ca86893 100644 --- a/views/profil.py +++ b/views/profil.py @@ -1,4 +1,4 @@ -from flask import Blueprint, Flask, request, flash, render_template, url_for, session, redirect, abort, make_response, send_file, escape, flash, abort +from flask import Blueprint, Flask, request, flash, render_template, url_for, session, redirect, abort, make_response, send_file, escape, flash, abort, send_from_directory from werkzeug.utils import secure_filename from PIL import Image import time @@ -30,12 +30,13 @@ BASE_URL = app.config['BASE_URL'] ################################################################################################## -@profil.route( '/parametres/', methods=['GET','POST'] ) -def parametres() : +@profil.route( '/profil/', methods=['GET'] ) +def profil_img(img) : if 'username' in session : - return render_template('parametres.html', section='profil') + UTILISATEUR='%s' % escape(session['username']) + return send_from_directory( os.path.join(DOSSIER_PERSO, UTILISATEUR, 'profile'), img ) else: - return redirect(url_for('loginlogout.login')) + return redirect(BASE_URL, code=401) @@ -76,13 +77,13 @@ def profile() : f.save(DOSSIER_PERSO + UTILISATEUR + '/profile/' + nom) image = DOSSIER_PERSO + UTILISATEUR + '/profile/' + nom with Image.open(image) as img: - img.tumbnails(resize='80x80') - img.save(filename = DOSSIER_PERSO + UTILISATEUR + '/profile/' + nom) - imagelocation = DOSSIER_PERSO + UTILISATEUR + '/profile/' + nom + img.thumbnail((300,200)) + img.save( DOSSIER_PERSO + UTILISATEUR + '/profile/' + nom) + filename = nom conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée cursor = conn.cursor() # Création de l'objet "curseur" cursor.execute("UPDATE users SET avatar=? WHERE name=?", - (imagelocation, UTILISATEUR)) + (filename, UTILISATEUR)) conn.commit() cursor = conn.cursor() # Création de l'objet "curseur" conn.close()