def add_path(parent_id, path_name): path = m.Path.query.get(parent_id) new_path = m.Path() new_path.text = path_name new_path.book_id = path.book_id m.db.session.add(new_path) m.db.session.commit() path.children.append(new_path) m.db.session.commit() return m.PathSchemaRoot().dump(new_path)
def end_path(id): path = m.Path.query.get(id) path.icon = 'fas fa-file' m.db.session.commit() return m.PathSchemaRoot().dump(path)
def rename_path(id, name): path = m.Path.query.get(id) path.text = name m.db.session.commit() return m.PathSchemaRoot().dump(path)
def delete_path(id): path = m.Path.query.get(id) path.old_parent = path.__dict__['parent'] path.parent = None m.db.session.commit() return m.PathSchemaRoot().dump(path)
def get_tree(book_id): path = m.Path.query.filter(m.Book.id == book_id) \ .first() return m.PathSchemaRoot().dump(path)