def update(_id): todo = TodoModel.find_by_id(_id) form = UpdateForm(obj=todo) if form.validate_on_submit(): todo.title = form.title.data todo.remarks = form.remarks.data todo.save_to_db() return redirect(url_for('view.home')) return render_template('update.html', form=form, todo=todo)
def delete(self, todo_id: str): """ Create new todo item""" try: todo = TodoModel.find_by_id(todo_id) if not todo: return {"success": True, "message": "deleted_succesfully"}, 200 todo.delete_from_db() except Exception as exception: logger.debug( f"Exception occured when deleting a todo with id: {todo_id}, {exception}", ) return {"success": False, "message": "internal_error"}, 500 return {"success": True, "message": "deleted_succesfully"}, 200
def put(self, todo_id: str): """ modify existing todo item""" req_data = self.parser.parse_args() try: todo = TodoModel.find_by_id(todo_id) if not todo: todo = TodoModel(**req_data, owner=get_jwt_identity()) else: todo.desc = req_data["desc"] todo.title = req_data["title"] todo.status = req_data["status"] todo.save_to_db() return {"success": True, "todo": todo.to_json()}, 200 except Exception as exception: logger.error( f"Exception occured when modifying a todo with params: {req_data}, {exception}", ) return {"sucess": False, "message": "internal_error"}, 500
def delete(_id): todo = TodoModel.find_by_id(_id) todo.delete_to_db() return redirect(url_for('view.home'))