def mark_todo_item_done_mongo(id): """ sets an existing todo in mongo to the done collection and deletes from the todo collection Args: item: The ID of the item to update. """ db = get_db(Config.MONGO_DB) todo = db.todo done = db.done done.insert_one(todo.find_one({"_id": ObjectId(id)})).inserted_id todo.delete_one(todo.find_one({"_id": ObjectId(id)})) return
def mark_done_item_doing_mongo(id): """ sets an existing done item in mongo to the doing collection and deletes from the done collection Args: item: The ID of the item to update. """ db = get_db(Config.MONGO_DB) done = db.done doing = db.doing doing.insert_one(done.find_one({"_id": ObjectId(id)})).inserted_id done.delete_one(done.find_one({"_id": ObjectId(id)})) return
def add_item_mongo(title): """ Adds a new item with the specified title to the Mongo DB. Args: title: The title of the item. Returns: item: The saved item. """ db = get_db(Config.MONGO_DB) newitem = {'title': title, "lastmodifieddate": datetime.datetime.utcnow()} todo = db.todo id = todo.insert_one(newitem).inserted_id return id
def get_items_mongo(): """ Fetches all cards from Mongo DB. Returns: list: The list of saved items. """ db = get_db(Config.MONGO_DB) items = [] todo = db.todo doing = db.doing done = db.done for item in todo.find(): items.append( Item(item['_id'], item['title'], item['lastmodifieddate'], "To Do")) for item in doing.find(): items.append( Item(item['_id'], item['title'], item['lastmodifieddate'], "Doing")) for item in done.find(): items.append( Item(item['_id'], item['title'], item['lastmodifieddate'], "Done")) return items