From 7ac982e2b5f2e7205afcf615cd984a5f89e93991 Mon Sep 17 00:00:00 2001 From: Kostanjevec Date: Wed, 15 Jun 2022 02:55:22 +0200 Subject: [PATCH] checking file duplicates seems to work, didnt check in could tho --- upload.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/upload.py b/upload.py index 9143d57..0c5e32d 100644 --- a/upload.py +++ b/upload.py @@ -34,26 +34,23 @@ def upload_file(): username = session["username"] if request.method == 'POST': - #flask gets the file - #print(list(request.files)[0][1]) - #upload = request.files["file"] - #print(upload) - - #uploads = list(request.files)[0] - #print(uploads) - print(request.files) + #@TODO ta forloop bi lahko flashal postopoma for upload in request.files.getlist("file"): filename = secure_filename(upload.filename) # Is there really a file? if not filename: flash('There is no file. Try again?') - return render_template("menu/upload.html", username=username) - script_path = os.path.dirname(os.path.abspath(__file__)) - temp_path = os.path.join(script_path, "temp") + #prevent duplicate filenames + print(filename) + if dbsession.query(Card).filter(Card.title == filename).first() != None: + flash("Filename already in database, please rename if you want to upload: " + filename, 'error') + continue + + script_path = os.path.dirname(os.path.abspath(__file__)) #where are we + temp_path = os.path.join(script_path, "temp") #where is the temp file - # @TODO ne dela za več fajlov # a lot of stuff can wrong here and nobody may know with tempfile.NamedTemporaryFile(dir=temp_path, delete=False) as fp: fp.write(upload.stream.read())