def search(self, ast): """Evaluate the AST and return a List of matching results.""" return [ Task.from_dict(doc) for doc in self._collection.find(self.__eval(ast.expression), projection={"_id": False}) ]
def import_file(filename, task_list): """Import tasks from filename into the configured task list""" import json with open(filename) as tasks_file: task = json.load(tasks_file) if isinstance(task, list): tasks = [Task.from_dict(t) for t in task] task_list.add_multiple(tasks) else: task_list.add(task)
def current(self): """Return the current task.""" doc = self._collection.find_one({ "completed_date": None, }, projection={"_id": False}, sort=[ ("priority", pymongo.DESCENDING), ("created_date", pymongo.ASCENDING), ]) return Task.from_dict(doc)
def run(args, task_list=None): """Open task by ID in $EDITOR. Update task based on result.""" try: if args['<ID>']: task = task_list.find_by_id(args['<ID>']) else: task = task_list.current() tmp = NamedTemporaryFile(mode='w+', suffix='.toml', delete=False) toml.dump(task.to_dict(), tmp) tmp.close() editor(tmp.name) with open(tmp.name) as tmp: new_task = Task.from_dict(toml.load(tmp)) task_list.update(new_task) os.remove(tmp.name) except NotFoundError: print('no task with that ID exists') sys.exit(1)
def find_by_id(self, task_id): """Find a task by task_id.""" return Task.from_dict( self._collection.find_one({"id": task_id}, projection={"_id": False}))
def list(self): """Return a python list of the Task in this List.""" return [ Task.from_dict(doc) for doc in self._collection.find(projection={"_id": False}) ]