def FUN_delete_user(id): if session.get("current_user", None) == "ADMIN": if id == "ADMIN": # ADMIN account can't be deleted. return abort(403) # [1] Delete this user's images in image pool images_to_remove = [x[0] for x in list_images_for_user(id)] for f in images_to_remove: image_to_delete_from_pool = [y for y in [x for x in os.listdir(app.config['UPLOAD_FOLDER'])] if y.split("-", 1)[0] == f][0] os.remove(os.path.join(app.config['UPLOAD_FOLDER'], image_to_delete_from_pool)) # [2] Delele the records in database files delete_user_from_db(id) return(redirect(url_for("FUN_admin"))) else: return abort(401)
def FUN_private(): if "current_user" in session.keys(): notes_list = read_note_from_db(session['current_user']) notes_table = zip([x[0] for x in notes_list],\ [x[1] for x in notes_list],\ [x[2] for x in notes_list],\ ["/delete_note/" + x[0] for x in notes_list]) images_list = list_images_for_user(session['current_user']) images_table = zip([x[0] for x in images_list],\ [x[1] for x in images_list],\ [x[2] for x in images_list],\ ["/delete_image/" + x[0] for x in images_list]) return render_template("private_page.html", notes = notes_table, images = images_table) else: return abort(401)