1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 from timelinelib.repositories.interface import CategoryRepository
20 from timelinelib.repositories.interface import EventRepository
21 from timelinelib.canvas.data import sort_categories
22
23
25
28
31
34
35 - def save(self, category):
37
38
40
43
44 - def save(self, event):
46
47
49 """
50 Transform flat list of categories to a tree based on parent attribute.
51
52 The top-level categories have the given parent and each level in the tree
53 is sorted.
54
55 If remove is given then the subtree with remove as root will not be
56 included.
57
58 The tree is represented as a list of tuples, (cat, sub-tree), where cat is
59 the parent category and subtree is the same tree representation of the
60 children.
61 """
62 children = [child for child in category_list
63 if (child.parent == parent and child != remove)]
64 sorted_children = sort_categories(children)
65 tree = [(x, category_tree(category_list, x, remove))
66 for x in sorted_children]
67 return tree
68