Ejemplo n.º 1
0
def build_model (db):
    conn = sqlite3.connect(db)
    contexts = query (conn, clazz=OFContext)
    project_infos = query (conn, clazz=ProjectInfo)
    folders = query (conn, clazz=OFFolder)
    tasks = query (conn, clazz=OFTask)
    
    projects = transmute_projects (project_infos, tasks)
    wire_projects_and_folders(projects, folders)
    wire_task_hierarchy(tasks)
    wire_tasks_to_enclosing_projects (project_infos, tasks)
    wire_tasks_and_contexts(contexts, tasks)
    wire_folder_hierarchy (folders)
    wire_context_hierarchy (contexts)
    
    conn.close ()
    
    # Find top level items
    project_roots = only_roots (projects.values())
    folder_roots = only_roots (folders.values())
    roots_projects_and_folders = project_roots + folder_roots
    root_contexts = only_roots (contexts.values())
    
    sort(roots_projects_and_folders)
    sort(root_contexts)
    
    return roots_projects_and_folders, root_contexts
Ejemplo n.º 2
0
def build_model(db):
    conn = sqlite3.connect(db)
    contexts = query(conn, clazz=OFContext)
    project_infos = query(conn, clazz=ProjectInfo)
    folders = query(conn, clazz=OFFolder)
    tasks = query(conn, clazz=OFTask)

    projects = transmute_projects(project_infos, tasks)
    wire_projects_and_folders(projects, folders)
    wire_task_hierarchy(tasks)
    wire_tasks_to_enclosing_projects(project_infos, tasks)
    wire_tasks_and_contexts(contexts, tasks)
    wire_folder_hierarchy(folders)
    wire_context_hierarchy(contexts)

    conn.close()

    # Find top level items
    project_roots = only_roots(projects.values())
    folder_roots = only_roots(folders.values())
    roots_projects_and_folders = project_roots + folder_roots
    root_contexts = only_roots(contexts.values())

    sort(roots_projects_and_folders)
    sort(root_contexts)

    return roots_projects_and_folders, root_contexts
Ejemplo n.º 3
0
 def test_sort_order_when_sorted (self):
     parent = SortableTask (name=u'p')
     n1 = SortableTask (name=u'n1')
     n2 = SortableTask (name=u'n2')
     parent.children.append (n1)
     parent.children.append (n2)
     
     sort ([parent])
     
     self.assertEqual(n1, parent.children[0])
     self.assertEqual(n2, parent.children[1])
Ejemplo n.º 4
0
    def test_sort_order_when_unsorted(self):
        parent = SortableTask(name=u'p')
        n2 = SortableTask(name=u'n2')
        n1 = SortableTask(name=u'n1')
        parent.children.append(n1)
        parent.children.append(n2)

        sort([parent])

        self.assertEqual(n1, parent.children[0])
        self.assertEqual(n2, parent.children[1])
Ejemplo n.º 5
0
 def test_sort_no_key_defined (self):
     parent = Task (name=u'p')
     n1 = Task (name=u'n1')
     n2 = Task (name=u'n2')
     parent.children.append (n1)
     parent.children.append (n2)
     
     try:
         sort ([parent])
         self.fail('exception expected')
     except Exception as e:
         self.assertEquals("not implemented in <class 'treemodel.Task'>", e.message)
Ejemplo n.º 6
0
    def test_sort_no_key_defined(self):
        parent = Task(name=u'p')
        n1 = Task(name=u'n1')
        n2 = Task(name=u'n2')
        parent.children.append(n1)
        parent.children.append(n2)

        try:
            sort([parent])
            self.fail('exception expected')
        except Exception as e:
            self.assertEquals("not implemented in <class 'treemodel.Task'>",
                              e.message)
Ejemplo n.º 7
0
def build_model (db):
    conn = sqlite3.connect(db)
    contexts = query (conn, clazz=OFContext)
    no_context = Context(name = 'No Context')
    inbox = Project (name='Inbox')
    project_infos = query (conn, clazz=ProjectInfo)
    folders = query (conn, clazz=OFFolder)
    tasks = query (conn, clazz=OFTask)
    
    projects = transmute_projects (project_infos, tasks)
    wire_projects_and_folders(projects, folders, tasks)
    wire_task_hierarchy(tasks)
    wire_tasks_to_enclosing_projects (project_infos, tasks, inbox)
    wire_tasks_and_contexts(contexts, tasks, no_context)
    wire_folder_hierarchy (folders)
    wire_context_hierarchy (contexts)
    
    conn.close ()
    
    # Find top level items
    project_roots = only_roots (projects.values())
    folder_roots = only_roots (folders.values())
    root_projects_and_folders = project_roots + folder_roots
    root_contexts = only_roots (contexts.values())
    root_contexts.insert(0, no_context)
    root_projects_and_folders.insert(0, inbox)
    sort(root_projects_and_folders)
    sort(root_contexts)
    
    root_folder = Folder (name='')
    for child in root_projects_and_folders:
        root_folder.add_child(child)
        
    root_context = Context (name='', status='active')
    for child in root_contexts:
        root_context.add_child(child)
        
    return root_folder, root_context
Ejemplo n.º 8
0
def build_model(db):
    conn = sqlite3.connect(db)
    contexts = query(conn, clazz=OFContext)
    no_context = Context(name='No Context')
    inbox = Project(name='Inbox')
    project_infos = query(conn, clazz=ProjectInfo)
    folders = query(conn, clazz=OFFolder)
    tasks = query(conn, clazz=OFTask)

    projects = transmute_projects(project_infos, tasks)
    wire_projects_and_folders(projects, folders, tasks)
    wire_task_hierarchy(tasks)
    wire_tasks_to_enclosing_projects(project_infos, tasks, inbox)
    wire_tasks_and_contexts(contexts, tasks, no_context)
    wire_folder_hierarchy(folders)
    wire_context_hierarchy(contexts)

    conn.close()

    # Find top level items
    project_roots = only_roots(projects.values())
    folder_roots = only_roots(folders.values())
    root_projects_and_folders = project_roots + folder_roots
    root_contexts = only_roots(contexts.values())
    root_contexts.insert(0, no_context)
    root_projects_and_folders.insert(0, inbox)
    sort(root_projects_and_folders)
    sort(root_contexts)

    root_folder = Folder(name='')
    for child in root_projects_and_folders:
        root_folder.add_child(child)

    root_context = Context(name='', status='active')
    for child in root_contexts:
        root_context.add_child(child)

    return root_folder, root_context