def get_personalized_data(key): user = User.get(key) todo_query = TodoItem.indexLookup("assigned_to_bin", key) todos = [] now = datetime.now() for todo in todo_query.run(): print todo.done if not todo.done: t = {"title" : todo.title, "desc" : todo.desc["html"]} if todo.duedate: t["time_remaining"] = (todo.duedate - now).total_seconds() else: t["time_remaining"] = None todos.append(t) todos.sort(key=lambda x: x["time_remaining"]) user_json = { "projects" : get_user_projects_with_simple(user), "todos" : todos, "name" : user.name } return user_json
def create_todo_item(project_key, json, author): duedate = json.get("duedate", None) if duedate: duedate = datetime.strptime(duedate, "%m/%d/%Y") ti = TodoItem(title=json["title"], desc=json.get("desc", ""), duedate=duedate, author=author) ti.addIndex("project_bin", project_key) assignee = json.get("assignee") if assignee: ti.addIndex("assigned_to_bin", assignee) category = json.get("categories") if category: ti.addIndex("category_bin", category) ti.save() return ti
def edit_todo_item(todo_key, json): todo = TodoItem.get(todo_key) if json.get("title"): todo.title = json["title"] if json.get("desc"): todo.desc = json["desc"] if json.get("duedate"): todo.duedate = datetime.strptime(json["duedate"], "%m/%d/%Y") if json["categories"]: todo.removeIndex("category_bin", silent=True) todo.addIndex("category_bin", json["categories"][0]) if json["assignee"] and json["assignee"] != "noone": todo.removeIndex("assigned_to_bin", silent=True) todo.addIndex("assigned_to_bin", json["assignee"]) todo.save() return todo
def get_todo_item_with_2i(field, value, simple=False): items_queries = TodoItem.indexLookup(field, value) items = [] # could probably simplify with an integer counter on where each sections are and insert. done_items = [] no_duedate = [] list_to_append_to = items for item in items_queries.run(): if item.done: list_to_append_to = done_items elif not item.duedate: list_to_append_to = no_duedate else: list_to_append_to = items if simple: list_to_append_to.append(todo_to_json_simple(item)) else: list_to_append_to.append(todo_to_json(item)) items.sort(key=lambda x: x["duedate"]) done_items.sort(key=lambda x:["duedate"]) items = items + no_duedate + done_items items.reverse() return items
def mark_todo_done(todo_key, done): todo = TodoItem.get(todo_key) todo.done = done todo.save()
def delete_todo_item(todo_key): TodoItem.get(todo_key).delete()
def get_todo_json(todo_key): return todo_to_json(TodoItem.get(todo_key))