def test_change_node_title(): node = library.get_index("Delete Me").nodes.children[0] schema.change_node_title(node, "Part1", "en", "1st Part") node = library.get_index("Delete Me").nodes.children[0] assert node.primary_title() == "1st Part" assert len(node.get_titles_object()) == 3 assert isinstance( Link().load({'refs': ['Delete Me, 1st Part 1:1', 'Shabbat 2a:5']}), Link) assert isinstance( Link().load( {'refs': ['Delete Me, 1st Part 2:1', 'Delete Me, Part2 2:1']}), Link) assert isinstance(Note().load({'ref': 'Delete Me, 1st Part 1:1'}), Note) assert Link().load( {'refs': ['Delete Me, Part1 2:1', 'Delete Me, Part2 2:1']}) is None assert Note().load({'ref': 'Delete Me, Part1 1:1'}) is None schema.change_node_title(node, "1st Part", "en", "Part1") node = library.get_index("Delete Me").nodes.children[0] assert node.primary_title() == "Part1" schema.change_node_title(node, "Partone", "en", "Part One") node = library.get_index("Delete Me").nodes.children[0] assert len(node.get_titles_object()) == 3 assert any( [title['text'] == 'Part One' for title in node.get_titles_object()]) schema.change_node_title(node, "Part One", "en", "Partone") assert len(node.get_titles_object()) == 3 assert any( [title['text'] == 'Partone' for title in node.get_titles_object()])
def replace_title(node): """ :param TitledTreeNode node: """ old_title = node.primary_title('en') if is_ascii(old_title): return things_to_replace = { '\xa0': '', '\u015b': 's', '\u2018': "'", '\u2019': "'" } new_title = multiple_replace(old_title, things_to_replace) if old_title == new_title: print("Can't fix {}".format(node.full_title('en'))) return print("Changing '{}' to '{}'".format(old_title, new_title)) change_node_title(node, old_title, 'en', new_title)
def replace_title(node): """ :param TitledTreeNode node: """ old_title = node.primary_title('en') if is_ascii(old_title): return things_to_replace = { u'\xa0': u'', u'\u015b': u's', u'\u2018': u"'", u'\u2019': u"'" } new_title = multiple_replace(old_title, things_to_replace) if old_title == new_title: print u"Can't fix {}".format(node.full_title('en')) return print u"Changing '{}' to '{}'".format(old_title, new_title) change_node_title(node, old_title, 'en', new_title)
def test_change_node_title(): node = library.get_index("Delete Me").nodes.children[0] schema.change_node_title(node, "Part1", "en", "1st Part") node = library.get_index("Delete Me").nodes.children[0] assert node.primary_title() == "1st Part" assert len(node.get_titles()) == 3 assert isinstance(Link().load({'refs': ['Delete Me, 1st Part 1:1', 'Shabbat 2a:5']}), Link) assert isinstance(Link().load({'refs': ['Delete Me, 1st Part 2:1', 'Delete Me, Part2 2:1']}), Link) assert isinstance(Note().load({'ref': 'Delete Me, 1st Part 1:1'}), Note) assert Link().load({'refs': ['Delete Me, Part1 2:1', 'Delete Me, Part2 2:1']}) is None assert Note().load({'ref': 'Delete Me, Part1 1:1'}) is None schema.change_node_title(node, "1st Part", "en", "Part1") node = library.get_index("Delete Me").nodes.children[0] assert node.primary_title() == "Part1" schema.change_node_title(node, "Partone", "en", "Part One") node = library.get_index("Delete Me").nodes.children[0] assert len(node.get_titles()) == 3 assert any([title['text'] == 'Part One' for title in node.get_titles()]) schema.change_node_title(node, "Part One", "en", "Partone") assert len(node.get_titles()) == 3 assert any([title['text'] == 'Partone' for title in node.get_titles()])
import django django.setup() from sefaria.model import * from sefaria.helper.schema import change_node_title i = library.get_index("Ohr Chadash") intro = i.nodes.children[0] preface = i.nodes.children[1] change_node_title(intro, "Introduction to Ohr Chadash", 'en', "Introduction") change_node_title(intro, "", 'he', "")
arrayMapNode.wholeRef = "{} {}".format(self.en_section, self.get_range()) arrayMapNode.includeSections = True arrayMapNode.validate() return arrayMapNode.serialize() # # from sefaria.helper.schema import change_node_title title = "Tur" print title print "Changing node titles" index = library.get_index(title) parent = index.nodes #change_node_title(parent.children[1], "Yoreh Deah", "en", "Yrh Dh") change_node_title(parent.children[1], u"יורה דעה", "he", u"יורה דאה") # # library.rebuild(include_toc=True) # for title in ["Tur", "Beit Yosef"]: # print title # print "Adding intro" # intro = JaggedArrayNode() # intro.add_shared_term("Introduction") # intro.key = "Introduction" # intro.add_structure(["Paragraph"]) # index = library.get_index(title) # reloading index to ensure we have the most up-to-date in memory # parent = index.nodes # insert_first_child(intro, parent) # links = [] # for sec_ref in library.get_index("Tur").all_section_refs():