def changeProfilePic(form): filename = form.img.file.filename if form.validate() and filename != DEFAULT_PROFILE_PIC and allowed_file(filename): # Delete the profile picture deleteProfilePic(current_user.img) # Store file filename = current_user.uname + '_' + secure_filename(form.img.data.filename) # Save to DB form.img.file.save(os.path.join(current_app.config['UPLOAD_FOLDER'], filename)) current_user.update(set__img=filename) current_user.save() # Successfully change pic flash("Successfully changed profile picture to %s" % filename)
def changeProfilePic(form): filename = form.img.file.filename if form.validate() and filename != DEFAULT_PROFILE_PIC and allowed_file(filename): # Remove old_profile pic from storage if current_user.img != DEFAULT_PROFILE_PIC: subprocess.call("rm -f photos/%s" % str(current_user.img), shell=True) # Store file filename = current_user.uname + '_' + secure_filename(form.img.data.filename) # Save to DB form.img.file.save(os.path.join(current_app.config['UPLOAD_FOLDER'], filename)) current_user.update(set__img=filename) current_user.save() # Successfully change pic flash("Successfully changed profile picture to %s" % filename) return render_template("settings.html", form=form, upform=UploadForm()) return render_template("settings.html", form=form, upform=UploadForm())