Skip to content

Instantly share code, notes, and snippets.

@Athira2199
Last active February 15, 2021 10:29
Show Gist options
  • Save Athira2199/daccaad205c5dccca23ed72d35da09b8 to your computer and use it in GitHub Desktop.
Save Athira2199/daccaad205c5dccca23ed72d35da09b8 to your computer and use it in GitHub Desktop.
#handler for updating todos
def update_handler():
updatedToDo = dict()
print('Enter to do id')
toDoId = input()
print('Enter name, leave as blank if update not required ')
name = input()
if(name != ""):
updatedToDo["name"] = name
print('Enter description, leave as blank if update not required ')
description = input()
if(description != ""):
updatedToDo["description"] = description
print('Enter status, leave as blank if update not required. Valid values ="done","doing","pending"')
status = input()
if(input == "done" or input =="doing" or input =="pending" or input == ""):
updatedToDo["status"] = status
updateStatus = update_todo(ObjectId(toDoId),updatedToDo)
if(updateStatus):
print("Operation Failed")
else:
print("Operation Success")
else:
print("Invalid status value. Operation terminated")
show_handler()
#update handler for individual todo
def update_todo(toDoId,updatedToDo):
try:
todo.update_one({"_id":toDoId},{"$set":updatedToDo})
return True
except:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment