Commit 0cbfc6a8 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Copy projects from parent to new sub todo items.

parent 4c7e5c54
...@@ -230,6 +230,9 @@ class TodoListDependencyTester(TopydoTest.TopydoTest): ...@@ -230,6 +230,9 @@ class TodoListDependencyTester(TopydoTest.TopydoTest):
self.todolist.add("Baz p:1 id:2") self.todolist.add("Baz p:1 id:2")
self.todolist.add("Buzz p:2") self.todolist.add("Buzz p:2")
self.todolist.add("Fnord") self.todolist.add("Fnord")
self.todolist.add("Something with +Project")
self.todolist.add("Another one with +Project")
self.todolist.add("Todo with +AnotherProject")
def test_check_dep(self): def test_check_dep(self):
children = self.todolist.children(self.todolist.todo(1)) children = self.todolist.children(self.todolist.todo(1))
...@@ -279,6 +282,32 @@ class TodoListDependencyTester(TopydoTest.TopydoTest): ...@@ -279,6 +282,32 @@ class TodoListDependencyTester(TopydoTest.TopydoTest):
self.assertTrue(todo4.has_tag('id', '4')) self.assertTrue(todo4.has_tag('id', '4'))
self.assertTrue(todo1.has_tag('p', '4')) self.assertTrue(todo1.has_tag('p', '4'))
def test_add_dep3(self):
"""
Test that projects are not added double.
"""
todo6 = self.todolist.todo(6)
todo7 = self.todolist.todo(7)
projects = todo7.projects().copy()
self.todolist.add_dependency(todo6, todo7)
self.assertEquals(projects, todo7.projects())
def test_add_dep4(self):
"""
Test that a new project is added to the sub todo.
"""
config("test/data/config3")
todo6 = self.todolist.todo(6)
todo8 = self.todolist.todo(8)
self.todolist.add_dependency(todo6, todo8)
self.assertEquals(set(["Project", "AnotherProject"]), todo8.projects())
def test_remove_dep1(self): def test_remove_dep1(self):
from_todo = self.todolist.todo(3) from_todo = self.todolist.todo(3)
to_todo = self.todolist.todo(4) to_todo = self.todolist.todo(4)
......
[dep]
append_parent_projects = 1
...@@ -23,3 +23,7 @@ sort_string = desc:importance,due,desc:priority ...@@ -23,3 +23,7 @@ sort_string = desc:importance,due,desc:priority
; For calculating importance ; For calculating importance
ignore_weekends = 1 ignore_weekends = 1
[dep]
; Add parent projects when adding sub todo items
append_parent_projects = 0
...@@ -33,7 +33,7 @@ class _Config: ...@@ -33,7 +33,7 @@ class _Config:
If p_path is given, that is the only configuration file that will be If p_path is given, that is the only configuration file that will be
read. read.
""" """
self.sections = ['topydo', 'tags', 'sort', 'ls'] self.sections = ['topydo', 'tags', 'sort', 'ls', 'dep']
self.defaults = { self.defaults = {
# topydo # topydo
...@@ -57,6 +57,9 @@ class _Config: ...@@ -57,6 +57,9 @@ class _Config:
'keep_sorted': '0', 'keep_sorted': '0',
'sort_string': 'desc:importance,due,desc:priority', 'sort_string': 'desc:importance,due,desc:priority',
'ignore_weekends': '1', 'ignore_weekends': '1',
# dep
'append_parent_projects': '0',
} }
self.config = {} self.config = {}
...@@ -138,6 +141,12 @@ class _Config: ...@@ -138,6 +141,12 @@ class _Config:
except ValueError: except ValueError:
return self.defaults['ignore_weekends'] == '1' return self.defaults['ignore_weekends'] == '1'
def append_parent_projects(self):
try:
return self.cp.getboolean('dep', 'append_parent_projects')
except ValueError:
return self.defaults['append_parent_projects'] == '1'
def _get_tag(self, p_tag): def _get_tag(self, p_tag):
try: try:
return self.config[p_tag] return self.config[p_tag]
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
A list of todo items. A list of todo items.
""" """
from topydo.lib.Config import config
from topydo.lib.Graph import DirectedGraph from topydo.lib.Graph import DirectedGraph
from topydo.lib.TodoListBase import TodoListBase from topydo.lib.TodoListBase import TodoListBase
...@@ -116,7 +117,20 @@ class TodoList(TodoListBase): ...@@ -116,7 +117,20 @@ class TodoList(TodoListBase):
return str(new_id) return str(new_id)
if p_from_todo != p_to_todo and not self._depgraph.has_edge(hash(p_from_todo), hash(p_to_todo)): def append_projects_to_subtodo():
"""
Appends projects in the parent todo item that are not present in
the sub todo item.
"""
if config().append_parent_projects():
for project in p_from_todo.projects() - p_to_todo.projects():
src = p_to_todo.source()
src += " +{}".format(project)
p_to_todo.set_source_text(src)
if p_from_todo != p_to_todo and not self._depgraph.has_edge(
hash(p_from_todo), hash(p_to_todo)):
dep_id = None dep_id = None
if p_from_todo.has_tag('id'): if p_from_todo.has_tag('id'):
dep_id = p_from_todo.tag_value('id') dep_id = p_from_todo.tag_value('id')
...@@ -127,6 +141,7 @@ class TodoList(TodoListBase): ...@@ -127,6 +141,7 @@ class TodoList(TodoListBase):
p_to_todo.add_tag('p', dep_id) p_to_todo.add_tag('p', dep_id)
self._depgraph.add_edge(hash(p_from_todo), hash(p_to_todo), dep_id) self._depgraph.add_edge(hash(p_from_todo), hash(p_to_todo), dep_id)
self._update_parent_cache() self._update_parent_cache()
append_projects_to_subtodo()
self.dirty = True self.dirty = True
def remove_dependency(self, p_from_todo, p_to_todo): 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