Commit 1f9e06e3 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Print list of newly active todos after completing/deleting them.

Recurring todos deserved some attention, since the new instance
after completing them pops up as a newly active task. This had to
be surpressed to measure the length of the todolist, and only
measure the new tasks within that range. Recurring tasks would be
added beyond that cut-off point.
parent bf851310
......@@ -60,7 +60,7 @@ class DeleteCommandTest(CommandTest.CommandTest):
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.todolist.todo(1).source(), "Foo")
self.assertEquals(self.output, "Removed: Bar p:1\n")
self.assertEquals(self.output, "Removed: Bar p:1\nThe following todo item(s) became active:\nFoo\n")
self.assertEquals(self.errors, "")
def test_del5(self):
......
......@@ -32,6 +32,7 @@ class DCommand(Command):
super(DCommand, self).__init__(p_args, p_todolist, p_out, p_err, p_prompt)
self.number = None
self.length = len(self.todolist.todos()) # to determine newly activated todos
self.force = self.argument_shift("--force") or self.argument_shift("-f")
try:
......@@ -71,16 +72,23 @@ class DCommand(Command):
self.execute_specific_core(child)
self.out(self.prefix() + pretty_print(child))
def _print_unlocked_todos(self):
"""
Print the items that became unlocked by marking this subitem
(self.todo) as complete.
def _print_unlocked_todos(self, p_old, p_new):
delta = [todo for todo in p_new if todo not in p_old]
if delta:
self.out("The following todo item(s) became active:")
self._print_list(delta, False)
def _active_todos(self):
"""
parents = [parent for parent in self.todolist.parents(self.todo) if not self._uncompleted_children(parent) and parent.is_active()]
Returns a list of active todos, taking uncompleted subtodos into
account.
if parents:
self.out("The following todo item(s) became active:")
self._print_list(parents, False)
The stored length of the todolist is taken into account, to prevent new
todos created by recurrence to pop up as newly activated tasks.
Since these todos pop up at the end of the list, we cut off the list
just before that point.
"""
return [todo for todo in self.todolist.todos()[:self.length] if not self._uncompleted_children(todo) and todo.is_active()]
def condition(self):
""" An additional condition whether execute_specific should be executed. """
......@@ -106,9 +114,11 @@ class DCommand(Command):
if not self.number:
self.error(self.usage())
elif self.todo and self.condition():
old_active = self._active_todos()
self._process_subtasks()
self.execute_specific()
self._print_unlocked_todos()
current_active = self._active_todos()
self._print_unlocked_todos(old_active, current_active)
elif not self.todo:
self.error("Invalid todo number given.")
else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment