Commits

edgimar  committed b6e5378

- read task-notes into TaskTree objects when getting data from Google
A task_notes instance-variable was added to the TaskTree class (which
probably should be called TaskNode). When Google is polled for task data,
and a Task-tree is built, each node's task_notes variable is populated. No
other behavioral changes have been made.

  • Participants
  • Parent commits 96e0a96

Comments (0)

Files changed (1)

File michel/michel.py

 import os.path
 import sys
 
-class TasksTree():
+class TasksTree(object):
     """
     Tree for holding tasks
 
     - may have a title
     """
 
-    def __init__(self, title=None, task_id=None):
-        """init"""
+    def __init__(self, title=None, task_id=None, task_notes=None):
         self.title = title
         self.task_id = task_id
         self.subtasks = []
+        self.task_notes = task_notes
 
     def get(self, task_id):
         """Returns the task of given id"""
                 if subtask.get(task_id) != None:
                     return subtask.get(task_id)
 
-    def add_subtask(self, title, task_id = None, parent_id = None):
+    def add_subtask(self, title, task_id = None, parent_id = None,
+            task_notes=None):
         """
         Adds a subtask to the tree
         - with the specified task_id
         - as a child of parent_id
         """
         if not parent_id:
-            self.subtasks.append(TasksTree(title, task_id))
+            self.subtasks.append(TasksTree(title, task_id, task_notes))
         else:
             if not self.get(parent_id):
                 raise ValueError, "No element with suitable parent id"
-            self.get(parent_id).add_subtask(title, task_id)
+            self.get(parent_id).add_subtask(title, task_id, None, task_notes)
 
     def last(self, level):
         """Returns the last task added at a given level of the tree"""
     while tasklist != [] and fail_count < 1000 :
         t = tasklist.pop(0)
         try:
-            tasks_tree.add_subtask(t['title'].encode('utf-8'), t['id'], t.get('parent'))
+            tasks_tree.add_subtask(t['title'].encode('utf-8'), t['id'],
+                    t.get('parent'), t.get('notes'))
         except ValueError:
             fail_count += 1
             tasklist.append(t)
             assert indent_lvl <= curr_indent_lvl + 1, ("line %d: "
                     "subtask has no parent task" % n)
             curr_indent_lvl = indent_lvl
-            tasks_tree.last(indent_lvl).add_subtask(line)
+            # TODO: Parse and add task_notes if they exist, not just title
+            # (line)
+            tasks_tree.last(indent_lvl).add_subtask(title=line) 
     return tasks_tree
 
 def push_todolist(path, list_id):