Commit 2befec11 authored by Bram Schoenmakers's avatar Bram Schoenmakers

When completing a subtask, print a list of activated todos.

A todo becomes activated when all its children have been completed and
the other active conditions apply as well (e.g. start date has passed).
parent 21c906a4
...@@ -38,10 +38,16 @@ class DoCommand(Command): ...@@ -38,10 +38,16 @@ class DoCommand(Command):
except (InvalidCommandArgument, InvalidTodoNumberException, InvalidTodoException): except (InvalidCommandArgument, InvalidTodoNumberException, InvalidTodoException):
self.todo = None self.todo = None
def _uncompleted_children(self, p_todo):
return sorted([t for t in self.todolist.children(p_todo) if not t.is_completed()])
def _print_list(self, p_todos):
self.out("\n".join(pretty_print_list(p_todos, [self.todolist.pp_number()])))
def _complete_children(self): def _complete_children(self):
children = sorted([t for t in self.todolist.children(self.todo) if not t.is_completed()]) children = self._uncompleted_children(self.todo)
if children: if children:
self.out("\n".join(pretty_print_list(children, [self.todolist.pp_number()]))) self._print_list(children)
if not self.force: if not self.force:
confirmation = self.prompt("Also mark subtasks as done? [n] ") confirmation = self.prompt("Also mark subtasks as done? [n] ")
...@@ -57,6 +63,17 @@ class DoCommand(Command): ...@@ -57,6 +63,17 @@ class DoCommand(Command):
self.todolist.add_todo(new_todo) self.todolist.add_todo(new_todo)
self.out(pretty_print(new_todo, [self.todolist.pp_number()])) self.out(pretty_print(new_todo, [self.todolist.pp_number()]))
def _print_unlocked_todos(self):
"""
Print the items that became unlocked by marking this subitem
(self.todo) as complete.
"""
parents = [parent for parent in self.todolist.parents(self.todo) if not self._uncompleted_children(parent) and parent.is_active()]
if parents:
self.out("The following todo item(s) became active:")
self._print_list(parents)
def execute(self): def execute(self):
if not super(DoCommand, self).execute(): if not super(DoCommand, self).execute():
return False return False
...@@ -68,6 +85,7 @@ class DoCommand(Command): ...@@ -68,6 +85,7 @@ class DoCommand(Command):
self._handle_recurrence() self._handle_recurrence()
self.todolist.set_todo_completed(self.todo) self.todolist.set_todo_completed(self.todo)
self.out(pretty_print(self.todo)) self.out(pretty_print(self.todo))
self._print_unlocked_todos()
elif not self.todo: elif not self.todo:
self.error("Invalid todo number given.") self.error("Invalid todo number given.")
else: else:
......
...@@ -34,10 +34,15 @@ class DoCommandTest(CommandTest.CommandTest): ...@@ -34,10 +34,15 @@ class DoCommandTest(CommandTest.CommandTest):
"Baz p:1", "Baz p:1",
"Recurring! rec:1d", "Recurring! rec:1d",
"x 2014-10-18 Already complete", "x 2014-10-18 Already complete",
"Inactive t:2030-12-31 id:2",
"Subtodo of inactive p:2",
] ]
self.todolist = TodoList.TodoList(todos) self.todolist = TodoList.TodoList(todos)
self.today = date.today().isoformat() self.today = date.today()
self.tomorrow = self.today + timedelta(1)
self.today = self.today.isoformat()
self.tomorrow = self.tomorrow.isoformat()
def test_do1(self): def test_do1(self):
command = DoCommand.DoCommand(["3"], self.todolist, self.out, self.error, _no_prompt) command = DoCommand.DoCommand(["3"], self.todolist, self.out, self.error, _no_prompt)
...@@ -102,22 +107,19 @@ class DoCommandTest(CommandTest.CommandTest): ...@@ -102,22 +107,19 @@ class DoCommandTest(CommandTest.CommandTest):
self.assertFalse(self.todolist.todo(2).is_completed()) self.assertFalse(self.todolist.todo(2).is_completed())
def test_recurrence(self): def test_recurrence(self):
today = date.today()
tomorrow = today + timedelta(1)
command = DoCommand.DoCommand(["4"], self.todolist, self.out, self.error) command = DoCommand.DoCommand(["4"], self.todolist, self.out, self.error)
self.assertFalse(self.todolist.todo(4).has_tag('due')) self.assertFalse(self.todolist.todo(4).has_tag('due'))
command.execute() command.execute()
todo = self.todolist.todo(6) todo = self.todolist.todo(8)
result = " 6 %s Recurring! rec:1d due:%s\nx %s Recurring! rec:1d\n" % (today.isoformat(), tomorrow.isoformat(), today.isoformat()) result = " 8 %s Recurring! rec:1d due:%s\nx %s Recurring! rec:1d\n" % (self.today, self.tomorrow, self.today)
self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.output, result) self.assertEquals(self.output, result)
self.assertEquals(self.errors, "") self.assertEquals(self.errors, "")
self.assertEquals(self.todolist.count(), 6) self.assertEquals(self.todolist.count(), 8)
self.assertTrue(self.todolist.todo(4).is_completed()) self.assertTrue(self.todolist.todo(4).is_completed())
self.assertFalse(todo.is_completed()) self.assertFalse(todo.is_completed())
self.assertTrue(todo.has_tag('due')) self.assertTrue(todo.has_tag('due'))
...@@ -138,6 +140,25 @@ class DoCommandTest(CommandTest.CommandTest): ...@@ -138,6 +140,25 @@ class DoCommandTest(CommandTest.CommandTest):
self.assertFalse(self.output) self.assertFalse(self.output)
self.assertEquals(self.errors, command.usage() + "\n") self.assertEquals(self.errors, command.usage() + "\n")
def test_activated_todos1(self):
command = DoCommand.DoCommand(["2"], self.todolist, self.out, self.error)
command.execute()
first_output = "x %s Bar p:1\n" % self.today
self.assertEquals(self.output, first_output)
self.assertEquals(self.errors, "")
command = DoCommand.DoCommand(["3"], self.todolist, self.out, self.error)
command.execute()
def test_activated_todos2(self):
command = DoCommand.DoCommand(["7"], self.todolist, self.out, self.error)
command.execute()
self.assertEquals(self.output, "x %s Subtodo of inactive p:2\n" % self.today)
self.assertEquals(self.errors, "")
def test_already_complete(self): def test_already_complete(self):
command = DoCommand.DoCommand(["5"], self.todolist, self.out, self.error) command = DoCommand.DoCommand(["5"], self.todolist, self.out, self.error)
command.execute() command.execute()
......
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