def process_category_name_change_in_categories_and_indexes(changed_cat, **kwargs): from sefaria.model.text import library old_toc_node = library.get_toc_tree().lookup(changed_cat.path[:-1] + [kwargs["old"]]) assert isinstance(old_toc_node, TocCategory) pos = len(old_toc_node.ancestors()) - 1 children = old_toc_node.all_children() for child in children: if isinstance(child, TocCategory): c = child.get_category_object() c.path[pos] = kwargs["new"] c.save(override_dependencies=True) for child in children: if isinstance(child, TocTextIndex): i = child.get_index_object() i.categories[pos] = kwargs["new"] i.save(override_dependencies=True)
def get_toc_object(self): from sefaria.model import library toc_tree = library.get_toc_tree() return toc_tree.lookup(self.path)