forked from bton/matekasse
remove tag button
This commit is contained in:
parent
1a4b38dfe2
commit
27c3981569
1 changed files with 21 additions and 6 deletions
|
@ -124,7 +124,7 @@ def create_app(test_config=None):
|
|||
tags = c.fetchall()
|
||||
text = ""
|
||||
for tag in tags:
|
||||
text = text + f"<p>{tag[0]}</p>"
|
||||
text = text + f'<p><form action="/removetag" method="post"><label for="removetag">{tag[0]} </label><input name="id" type="hidden" value="{user[0]}"><input name="tagid" type="hidden" value="{tag[0]}"><button id="removetag" type="submit">Remove Tag</button></form> </p>'
|
||||
return f"""<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js" integrity="sha512-q/dWJ3kcmjBLU4Qc47E4A9kTB4m3wuTY7vkFJDTZKjTs8jhyGQnaUrxa0Ytd0ssMZhbNua9hE+E7Qv1j+DyZwA==" crossorigin="anonymous"></script>
|
||||
|
@ -273,10 +273,25 @@ def create_app(test_config=None):
|
|||
user_id = int(request.form["id"])
|
||||
except: #except im Normalen Code!
|
||||
return render_template("error.html", error_code="043")
|
||||
session_id = uuid.uuid4()
|
||||
session[id] = session_id
|
||||
user_queue.put([user_id, "remove", session_id])
|
||||
return render_template("removetag.html", user=user_id)
|
||||
try:
|
||||
tag_id = int(request.form["tagid"])
|
||||
except:
|
||||
session_id = uuid.uuid4()
|
||||
session[id] = session_id
|
||||
user_queue.put([user_id, "remove", session_id])
|
||||
return render_template("removetag.html", user=user_id)
|
||||
else:
|
||||
db = get_db()
|
||||
c = db.cursor()
|
||||
c.execute(f"SELECT * FROM tags WHERE (tagid = ? AND userid = ?)", [tag_id, user_id])
|
||||
if c.fetchall != []:
|
||||
c.execute(f"DELETE FROM tags WHERE (tagid = ? AND userid = ?)", [tag_id, user_id])
|
||||
db.commit()
|
||||
message = f"Removed {tag_id} from user {user_id}"
|
||||
log(type="removetag", userid=user_id, before=tag_id)
|
||||
return message
|
||||
else:
|
||||
return render_template("error.html", error_code="054")
|
||||
|
||||
@socketio.on('removetag')
|
||||
def request_removetag(data):
|
||||
|
|
Loading…
Reference in a new issue