diff --git a/app.py b/app.py index d956d9f..b566f80 100644 --- a/app.py +++ b/app.py @@ -162,6 +162,13 @@ 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: diff --git a/database.py b/database.py index 66244ae..d05efbc 100644 --- a/database.py +++ b/database.py @@ -42,7 +42,9 @@ def delete_user_from_db(id): _conn.commit() _conn.close() - # when we delete a user from database USERS, we also need to delete all his or her images data from database IMAGES + # when we delete a user from database USERS, we also need to + # [1] delete all his or her images from image pool (done in app.py) + # [2] delete all his or her images records from database IMAGES _conn = sqlite3.connect(image_db_file_location) _c = _conn.cursor() _c.execute("delete from images where owner = '" + id + "';") diff --git a/database_file/images.db b/database_file/images.db index 1b63bde..8cd3d68 100644 Binary files a/database_file/images.db and b/database_file/images.db differ diff --git a/database_file/notes.db b/database_file/notes.db index 4bd9ed2..e1b8200 100644 Binary files a/database_file/notes.db and b/database_file/notes.db differ diff --git a/database_file/users.db b/database_file/users.db index eecd029..ce5a1a1 100644 Binary files a/database_file/users.db and b/database_file/users.db differ diff --git a/image_pool/e7c589f2627e1dac3fb9d57ad9ccd6066e67ce31-flask.png b/image_pool/cbebc37b8e9ae56d722fc3966bb78da4ce48f9a6-flask.png similarity index 100% rename from image_pool/e7c589f2627e1dac3fb9d57ad9ccd6066e67ce31-flask.png rename to image_pool/cbebc37b8e9ae56d722fc3966bb78da4ce48f9a6-flask.png