Commit 43da2315 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Merge pull request #12 from mruwek/append_parent_contexts

Append parent contexts
parents 5718e113 95baa9ef
......@@ -192,6 +192,26 @@ class AddCommandTest(CommandTest.CommandTest):
self.assertEquals(self.output, "|5dh| {today} Bar p:1 +Project\n|5dh| {today} Bar +Project\n".format(today=self.today))
def test_add_dep10(self):
"""
The text ID shown after adding and after an 'ls' must be equal."
By appending the parent's contexts, the textual ID may change.
"""
config("test/data/todolist-uid-contexts.conf")
# pass identitiy function to for writing output, we're not interested
# in this output
command = AddCommand.AddCommand(["Foo @Context"], self.todolist, lambda t: t, self.error)
command.execute()
command = AddCommand.AddCommand(["Bar before:x2k"], self.todolist, self.out, self.error)
command.execute()
command = ListCommand.ListCommand(["Bar"], self.todolist, self.out, self.error)
command.execute()
self.assertEquals(self.output, "|5dc| {today} Bar p:1 @Context\n|5dc| {today} Bar @Context\n".format(today=self.today))
def test_add_reldate1(self):
command = AddCommand.AddCommand(["Foo due:today"], self.todolist, self.out, self.error)
command.execute()
......
[topydo]
identifiers = text
[dep]
append_parent_contexts = 1
......@@ -28,3 +28,5 @@ ignore_weekends = 1
[dep]
; Add parent projects when adding sub todo items
append_parent_projects = 0
; Add parent contexts when adding sub todo items
append_parent_contexts = 0
......@@ -61,6 +61,7 @@ class _Config:
# dep
'append_parent_projects': '0',
'append_parent_contexts': '0',
}
self.config = {}
......@@ -148,6 +149,12 @@ class _Config:
except ValueError:
return self.defaults['append_parent_projects'] == '1'
def append_parent_contexts(self):
try:
return self.cp.getboolean('dep', 'append_parent_contexts')
except ValueError:
return self.defaults['append_parent_contexts'] == '1'
def _get_tag(self, p_tag):
try:
return self.config[p_tag]
......
......@@ -141,6 +141,15 @@ class TodoList(TodoListBase):
for project in p_from_todo.projects() - p_to_todo.projects():
self.append(p_to_todo, "+{}".format(project))
def append_contexts_to_subtodo():
"""
Appends contexts in the parent todo item that are not present in
the sub todo item.
"""
if config().append_parent_contexts():
for context in p_from_todo.contexts() - p_to_todo.contexts():
self.append(p_to_todo, "@{}".format(context))
if p_from_todo != p_to_todo and not self._depgraph.has_edge(
hash(p_from_todo), hash(p_to_todo)):
......@@ -155,6 +164,7 @@ class TodoList(TodoListBase):
self._depgraph.add_edge(hash(p_from_todo), hash(p_to_todo), dep_id)
self._update_parent_cache()
append_projects_to_subtodo()
append_contexts_to_subtodo()
self.dirty = True
def remove_dependency(self, p_from_todo, p_to_todo):
......
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