def execute(self): if not super().execute(): return False try: expression = self.argument(0) except InvalidCommandArgument: expression = config().sort_string() sorter = Sorter(expression) # TODO: validate sorted_todos = sorter.sort(self.todolist.todos()) self.todolist.replace(sorted_todos)
def execute(self): if not super().execute(): return False try: expression = self.argument(0) except InvalidCommandArgument: expression = config().sort_string() sorter = Sorter(expression) # TODO: validate sorted_todos = sorter.sort(self.todolist.todos()) self.todolist.replace(sorted_todos)
def execute(self): if not super(SortCommand, self).execute(): return False try: expression = self.argument(0) except InvalidCommandArgument: expression = config().sort_string() sorter = Sorter(expression) # TODO: validate sorted_todos = sorter.sort(self.todolist.todos()) self.todolist.erase() for todo in sorted_todos: self.todolist.add_todo(todo)
def sorted_todos_by_project(cfg, todo_cfg=None): """ Takes our todo list, and returns two dictionaries of where the keys equal to the project name, and the value is a list of todo items under that project. - Note that a todo item may be appended to multiple second level HTML lists if the item is listed under multiple projects. - Note that todo items without a project are discarded. - Note that completed items beyond `completion_cutoff` (measured in days) are discarded. todo_cfg is called to topydo.config directs as the path of the test configuration. Setting this to None will use the normal configuration. """ ''' print(type(cfg)) print(cfg) print(type(cfg['todo']), cfg['todo']) print(type(cfg['todo']['completion_cutoff']), cfg['todo']['completion_cutoff']) ''' completion_range = timestring.Range('last {!s} days'.format(cfg['todo']['completion_cutoff'])) my_sorter = Sorter(p_sortstring=cfg['todo']['sort_string']) todofile = TodoFile.TodoFile(topydo_config(todo_cfg).todotxt()) # print('Loaded todo file from {}'.format(todofile.path)) todotodos = TodoList.TodoList(todofile.read()) # todolist = my_sorter.sort(todolist) # in topydo v0.10 # json_str = JsonPrinter().print_list(todolist) # in topydo v0.10 todolist = my_sorter.sort(todotodos.todos()) # sort before filters # filters return a list, so apply them all at once? todolist = HiddenTagFilter().filter(todolist) todo_json_str = JsonPrinter().print_list(todolist) todo_json = json.loads(todo_json_str) donefile = TodoFile.TodoFile(topydo_config(todo_cfg).archive()) # print('Loaded done file from {}'.format(donefile.path)) donetodos = TodoList.TodoList(donefile.read()) donelist = my_sorter.sort(donetodos.todos()) donelist = HiddenTagFilter().filter(donelist) done_json_str = JsonPrinter().print_list(donelist) done_json = json.loads(done_json_str) active_todos = {} completed_todos = {} for my_json in [todo_json, done_json]: for todo in my_json: if not todo['completed']: for project in todo['projects']: try: active_todos[project].append(todo['source']) except KeyError: active_todos[project] = [todo['source']] else: completion_date = timestring.Date(todo['completion_date']) if completion_date in completion_range: for project in todo['projects']: try: completed_todos[project].append(todo['source']) except KeyError: completed_todos[project] = [todo['source']] return active_todos, completed_todos