Ensure image files & Record can be cleaned when a user is removed

This commit is contained in:
XD-DENG
2017-07-08 11:39:59 +08:00
parent 4b693ddb69
commit 961f17c2f5
6 changed files with 10 additions and 1 deletions

7
app.py
View File

@@ -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:

View File

@@ -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 + "';")

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

Before

Width:  |  Height:  |  Size: 208 KiB

After

Width:  |  Height:  |  Size: 208 KiB