def create_tree(story=None,story_id=None): if story_id is None: story_id = story.id from dbapi.paragraph import Paragraph paragraphs = Paragraph.get_approved_paragraphs(story_id) tree = dict((p.id, ParagraphNode(p)) for p in paragraphs) # Fill out the node data root = None for p in paragraphs: if p.parent_id != -1: tree[p.id].parent = tree[p.parent_id] tree[p.parent_id].children.append(tree[p.id]) else: root = tree[p.id] # Return the root node return root
def get_approved_paragraphs(self): return Paragraph.get_approved_paragraphs(self.id)