|
|
@@ -15,7 +15,6 @@ def new():
|
|
15
|
15
|
if request.method == 'POST':
|
|
16
|
16
|
name = request.form['name']
|
|
17
|
17
|
bio = request.form['bio']
|
|
18
|
|
- #icon = request.form['icon']
|
|
19
|
18
|
user_id = g.user[0]
|
|
20
|
19
|
db = get_db()
|
|
21
|
20
|
error = None
|
|
|
@@ -52,12 +51,41 @@ def edit(mid):
|
|
52
|
51
|
db.commit()
|
|
53
|
52
|
|
|
54
|
53
|
if "file" in request.files:
|
|
|
54
|
+ # here we are just saving the uploaded file to the icons folder.
|
|
|
55
|
+ # we're not going hard on security because we expect there to only be 1 admin
|
|
|
56
|
+ # but the filename will always be changed to a random string of numbers and letters known as uuid
|
|
55
|
57
|
file = request.files["file"]
|
|
56
|
58
|
filename = str(uuid.uuid4()) + "." + file.filename.split(".")[1]
|
|
57
|
|
- file.save(os.path.join(current_app.config["UPLOAD_FOLDER"], filename))
|
|
|
59
|
+ file.save(os.path.join(current_app.config["ICON_UPLOAD_FOLDER"], filename))
|
|
58
|
60
|
db.execute("INSERT INTO icons (member_id, icon_location) VALUES (?, ?)", (mid, filename),)
|
|
59
|
61
|
db.commit()
|
|
60
|
62
|
|
|
|
63
|
+ # this specific chunk here is checking whether icons in the myriad/static/icons folder have a link in the database
|
|
|
64
|
+ # in case the database was rebuilt, or something else happened, it is a waste of storage keeping an unlinked image
|
|
|
65
|
+ icons = db.execute("SELECT * FROM icons").fetchall()
|
|
|
66
|
+ icon_storage = os.listdir(current_app.config["ICON_UPLOAD_FOLDER"])
|
|
|
67
|
+ for icon in icon_storage:
|
|
|
68
|
+ in_database = False
|
|
|
69
|
+ for i in icons:
|
|
|
70
|
+ print(i[2], icon)
|
|
|
71
|
+ if i[2] == icon:
|
|
|
72
|
+ in_database = True
|
|
|
73
|
+ if not in_database:
|
|
|
74
|
+ os.remove(os.path.join(current_app.config["ICON_UPLOAD_FOLDER"], icon))
|
|
|
75
|
+
|
|
|
76
|
+ # and now for the same in reverse - clean the database of references to images that don't exist
|
|
|
77
|
+ for i in icons:
|
|
|
78
|
+ in_storage = False
|
|
|
79
|
+ print(i[2], i[0])
|
|
|
80
|
+ if i[2] in icon_storage:
|
|
|
81
|
+ in_storage = True
|
|
|
82
|
+ if not in_storage:
|
|
|
83
|
+ db.execute("DELETE FROM icons WHERE id=(?)", (i[0],),)
|
|
|
84
|
+ db.commit()
|
|
|
85
|
+
|
|
|
86
|
+ # the above cleanup operations should be a button in the manage sidebar but for now they are here.
|
|
|
87
|
+
|
|
|
88
|
+
|
|
61
|
89
|
member = db.execute("SELECT * FROM member WHERE id=(?)",(mid,)).fetchone()
|
|
62
|
90
|
icons = db.execute("SELECT * FROM icons WHERE member_id=(?)",(mid,)).fetchall()
|
|
63
|
91
|
return render_template("manage/edit.html", member=member, icons=icons)
|
|
|
@@ -71,4 +99,22 @@ def set_main_icon(mid, icon_id):
|
|
71
|
99
|
db.execute("UPDATE member SET main_icon=(?) WHERE id=(?)",(icon_id, mid))
|
|
72
|
100
|
db.commit()
|
|
73
|
101
|
|
|
74
|
|
- return redirect(url_for("manage.edit", mid=mid))
|
|
|
102
|
+ return redirect(url_for("manage.edit", mid=mid))
|
|
|
103
|
+
|
|
|
104
|
+@bp.route("/add_to_front/<mid>")
|
|
|
105
|
+@login_required
|
|
|
106
|
+def add_to_front(mid):
|
|
|
107
|
+ db = get_db()
|
|
|
108
|
+ db.execute("UPDATE member SET front=(?) WHERE id=(?)",(1, mid))
|
|
|
109
|
+ db.commit()
|
|
|
110
|
+
|
|
|
111
|
+ return redirect(url_for('home.full_list'))
|
|
|
112
|
+
|
|
|
113
|
+@bp.route("/remove_front/<mid>")
|
|
|
114
|
+@login_required
|
|
|
115
|
+def remove_front(mid):
|
|
|
116
|
+ db = get_db()
|
|
|
117
|
+ db.execute("UPDATE member SET front=(?) WHERE id=(?)",(0, mid))
|
|
|
118
|
+ db.commit()
|
|
|
119
|
+
|
|
|
120
|
+ return redirect(url_for('home.full_list'))
|