Remove User tag list
This commit is contained in:
parent
54b3f8c049
commit
9233e716b2
1 changed files with 20 additions and 7 deletions
27
main.py
27
main.py
|
@ -50,8 +50,13 @@ def user_info():
|
||||||
c.execute("SELECT * FROM users WHERE username = '%s'" % username)
|
c.execute("SELECT * FROM users WHERE username = '%s'" % username)
|
||||||
user = c.fetchall()
|
user = c.fetchall()
|
||||||
if user != []:
|
if user != []:
|
||||||
user = user[0]
|
user[0]
|
||||||
return f'<p>{user[1]}: {user[2]} <p><form action="/addtag" method="get"><input name="id" type="hidden" value="{user[0]}"><button type="submit">Add Tag</button></form><form action="/removetag" method="get"><input name="id" type="hidden" value="{user[0]}"><button type="submit">Remove Tag</button></form></p><form action="/change" method="get"><input name="id" type="hidden" value="{user[0]}"> Change balance: <input name="change"><input type="submit"></form></p>'
|
c.execute(f"SELECT * FROM tags WHERE userid={user[0]}")
|
||||||
|
tags = c.fetchall()
|
||||||
|
text = ""
|
||||||
|
for tag in tags:
|
||||||
|
text = text + f"<p>{tag[0]}</p>"
|
||||||
|
return f'<p>{user[1]}: {user[2]} <p><form action="/addtag" method="get"><input name="id" type="hidden" value="{user[0]}"><button type="submit">Add Tag</button></form><form action="/removetag" method="get"><input name="id" type="hidden" value="{user[0]}"><button type="submit">Remove Tag</button></form></p><form action="/change" method="get"><input name="id" type="hidden" value="{user[0]}"> Change balance: <input name="change"><input type="submit"></form></p><br></br><p>Tags:</p>{text}<br></br><form action="/removeuser" method="get"><input name="id" type="hidden" value="{user[0]}"><button type="submit">Remove User</button></form>{text}'
|
||||||
else:
|
else:
|
||||||
return "User does not exists"
|
return "User does not exists"
|
||||||
|
|
||||||
|
@ -59,6 +64,13 @@ def user_info():
|
||||||
def new_user():
|
def new_user():
|
||||||
return render_template("adduser.html")
|
return render_template("adduser.html")
|
||||||
|
|
||||||
|
@app.route("/removeuser", methode=['GET'])
|
||||||
|
def remove_user():
|
||||||
|
user_id = request.args.get("id")
|
||||||
|
c.execute(f"DELETE * FROM tags WHERE (userid = {user_id}) ") #Ist hier noch eine Bestätigung nötig?
|
||||||
|
c.execute(f"DELETE * FROM users WHERE (id={user_id})")
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
@app.route("/adduser/user", methods=['GET'])
|
@app.route("/adduser/user", methods=['GET'])
|
||||||
def adduser():
|
def adduser():
|
||||||
user = request.args.get("username")
|
user = request.args.get("username")
|
||||||
|
@ -122,9 +134,9 @@ def request_addtag(data):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
finished = None
|
finished = None
|
||||||
c.execute(f"SELECT * FROM users WHERE id ={user}")
|
c.execute(f"SELECT * FROM users WHERE id ={user[0]}")
|
||||||
username = c.fetchall()[0][1]
|
username = c.fetchall()[0][1]
|
||||||
c.execute(f"SELECT * FROM tags WHERE userid={user}")
|
c.execute(f"SELECT * FROM tags WHERE userid={user[0]}")
|
||||||
tag_id = c.fetchall()[0][0]
|
tag_id = c.fetchall()[0][0]
|
||||||
socketio.emit("finished", f"Added {tag_id} to {username}", to=session[id])
|
socketio.emit("finished", f"Added {tag_id} to {username}", to=session[id])
|
||||||
else:
|
else:
|
||||||
|
@ -150,10 +162,11 @@ def request_removetag(data):
|
||||||
global finished
|
global finished
|
||||||
join_room(session[id])
|
join_room(session[id])
|
||||||
if len(users.queue) > 0:
|
if len(users.queue) > 0:
|
||||||
user = users.queue[len(users.queue) - 1]
|
queue_item = users.queue[len(users.queue) - 1]
|
||||||
|
user = queue[0]
|
||||||
print(user)
|
print(user)
|
||||||
print(session[id])
|
print(session[id])
|
||||||
if user == [data["data"], "remove", session[id]]:
|
if queue_item == [data["data"], "remove", session[id]]:
|
||||||
socketio.emit("wait", "wait", to=session[id])
|
socketio.emit("wait", "wait", to=session[id])
|
||||||
i = 0
|
i = 0
|
||||||
print(session[id])
|
print(session[id])
|
||||||
|
@ -195,7 +208,7 @@ def get_id():
|
||||||
if state == "add":
|
if state == "add":
|
||||||
c.execute(f"INSERT OR IGNORE INTO tags (tagid, userid) VALUES ({tag_id}, {user})")
|
c.execute(f"INSERT OR IGNORE INTO tags (tagid, userid) VALUES ({tag_id}, {user})")
|
||||||
elif state == "remove":
|
elif state == "remove":
|
||||||
c.execute(f"DELETE FROM tags WHERE (tagid = {tag_id} AND userid = {user}) ")
|
c.execute(f"DELETE * FROM tags WHERE (tagid = {tag_id} AND userid = {user}) ")
|
||||||
conn.commit()
|
conn.commit()
|
||||||
finished = queue_item
|
finished = queue_item
|
||||||
return make_response("True")
|
return make_response("True")
|
||||||
|
|
Loading…
Reference in a new issue