Error message for remove and add tag
This commit is contained in:
parent
4ab5dd3e7e
commit
6ba0804eb1
1 changed files with 23 additions and 4 deletions
27
main.py
27
main.py
|
@ -157,6 +157,7 @@ def get_addtag_request():
|
||||||
@socketio.on('addtag')
|
@socketio.on('addtag')
|
||||||
def request_addtag(data):
|
def request_addtag(data):
|
||||||
global finished
|
global finished
|
||||||
|
global message
|
||||||
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]
|
user = users.queue[len(users.queue) - 1]
|
||||||
|
@ -174,7 +175,10 @@ def request_addtag(data):
|
||||||
finished = None
|
finished = None
|
||||||
c.execute(f"SELECT * FROM users WHERE id ={user[0]}")
|
c.execute(f"SELECT * FROM users WHERE id ={user[0]}")
|
||||||
username = c.fetchall()[0][1]
|
username = c.fetchall()[0][1]
|
||||||
socketio.emit("finished", f"Added tag to {username}", to=session[id]) #print tagid
|
if message == "Tag already exists":
|
||||||
|
socketio.emit("finished", f"{message}")
|
||||||
|
else:
|
||||||
|
socketio.emit("finished", f"Added {message} to {username}", to=session[id]) #print tagid
|
||||||
else:
|
else:
|
||||||
socketio.emit("busy", "busy", to=session[id])
|
socketio.emit("busy", "busy", to=session[id])
|
||||||
else:
|
else:
|
||||||
|
@ -196,6 +200,7 @@ def get_removetag_request():
|
||||||
@socketio.on('removetag')
|
@socketio.on('removetag')
|
||||||
def request_removetag(data):
|
def request_removetag(data):
|
||||||
global finished
|
global finished
|
||||||
|
global message
|
||||||
join_room(session[id])
|
join_room(session[id])
|
||||||
if len(users.queue) > 0:
|
if len(users.queue) > 0:
|
||||||
queue_item = users.queue[len(users.queue) - 1]
|
queue_item = users.queue[len(users.queue) - 1]
|
||||||
|
@ -215,7 +220,10 @@ def request_removetag(data):
|
||||||
finished = None
|
finished = None
|
||||||
c.execute(f"SELECT * FROM users WHERE id ={user}")
|
c.execute(f"SELECT * FROM users WHERE id ={user}")
|
||||||
username = c.fetchall()[0][1]
|
username = c.fetchall()[0][1]
|
||||||
socketio.emit("finished", f"removed tag from {username}")
|
if message == "Tag does not exist":
|
||||||
|
socketio.emit("finished", f"{message}")
|
||||||
|
else:
|
||||||
|
socketio.emit("finished", f"removed {message} from {username}")
|
||||||
else:
|
else:
|
||||||
socketio.emit("busy", "busy", to=session[id])
|
socketio.emit("busy", "busy", to=session[id])
|
||||||
else:
|
else:
|
||||||
|
@ -226,6 +234,7 @@ def request_removetag(data):
|
||||||
@app.route("/api/tag_id", methods=['GET'])
|
@app.route("/api/tag_id", methods=['GET'])
|
||||||
def get_id():
|
def get_id():
|
||||||
global finished
|
global finished
|
||||||
|
global messages
|
||||||
tag_id = int(request.args.get("id"))
|
tag_id = int(request.args.get("id"))
|
||||||
c.execute(f"SELECT * FROM tags WHERE tagid ={tag_id}")
|
c.execute(f"SELECT * FROM tags WHERE tagid ={tag_id}")
|
||||||
|
|
||||||
|
@ -238,9 +247,19 @@ def get_id():
|
||||||
state = queue_item[1]
|
state = queue_item[1]
|
||||||
print(state)
|
print(state)
|
||||||
if state == "add":
|
if state == "add":
|
||||||
c.execute(f"INSERT OR IGNORE INTO tags (tagid, userid) VALUES ({tag_id}, {user})")
|
c.execute(f"SELECT * FROM tags WHERE tagid={tag_id}")
|
||||||
|
if c.fetchall() != []:
|
||||||
|
message = "Tag already exists"
|
||||||
|
else:
|
||||||
|
c.execute(f"INSERT OR IGNORE INTO tags (tagid, userid) VALUES ({tag_id}, {user})")
|
||||||
|
message = tag_id
|
||||||
elif state == "remove":
|
elif state == "remove":
|
||||||
c.execute(f"DELETE FROM tags WHERE (tagid = {tag_id} AND userid = {user}) ")
|
c.execute(f"SELECT * FROM tags WHERE (tagid = {tag_id} AND userid = {user})")
|
||||||
|
if c.fetchall != []:
|
||||||
|
c.execute(f"DELETE FROM tags WHERE (tagid = {tag_id} AND userid = {user}) ")
|
||||||
|
message = tag_id
|
||||||
|
else:
|
||||||
|
message = "Tag does not exist"
|
||||||
conn.commit()
|
conn.commit()
|
||||||
finished = queue_item
|
finished = queue_item
|
||||||
socketio.emit("update", "update")
|
socketio.emit("update", "update")
|
||||||
|
|
Loading…
Reference in a new issue