Ejemplo n.º 1
0
def alter_schema(schema, new_index_title, new_index_he_title):
    schema["key"] = schema["title"] = new_index_title
    schema["heTitle"] = new_index_he_title
    title_group = TitleGroup()
    title_group.add_title(new_index_title, 'en', primary=True)
    title_group.add_title(new_index_he_title, 'he', primary=True)
    title_group.validate()
    schema["titles"] = title_group.titles
    return schema
Ejemplo n.º 2
0
def alter_schema(schema, new_index_title, new_index_he_title):
    schema["key"] = schema["title"] = new_index_title
    schema["heTitle"] = new_index_he_title
    title_group = TitleGroup()
    title_group.add_title(new_index_title, 'en', primary=True)
    title_group.add_title(new_index_he_title, 'he', primary=True)
    title_group.validate()
    schema["titles"] = title_group.titles
    return schema
Ejemplo n.º 3
0
def schema_with_default(simple_ja):
    """
    Take a standard JaggedArrayNode and makes it a default child of a SchemaNode.
    :param JaggedArrayNode simple_ja:
    :return: SchemaNode
    """
    root_node = SchemaNode()
    root_node.title_group = simple_ja.title_group
    root_node.key = simple_ja.key
    simple_ja.title_group = TitleGroup()
    simple_ja.key = "default"
    simple_ja.default = True
    root_node.append(simple_ja)
    root_node.validate()
    return root_node
Ejemplo n.º 4
0
def convert_jagged_array_to_schema_with_default(ja_node):
    from sefaria.model.schema import TitleGroup

    assert isinstance(ja_node, JaggedArrayNode)
    assert len(ja_node.children) == 0
    parent = ja_node.parent
    assert parent, "Use convert_simple_index_to_complex instead."
    assert isinstance(parent, SchemaNode)
    index = ja_node.index

    vs = [v for v in index.versionSet()]
    for v in vs:
        assert isinstance(v, Version)
        old_parent_content = v.content_node(parent)
        content = old_parent_content.pop(ja_node.key)  # Pop old JA content off
        old_parent_content[ja_node.key] = {
            "default": content
        }  # Re-add it as a default node
        v.save(override_dependencies=True)

    # Find place of ja_node in parent's children
    index_of_ja_node = parent.children.index(ja_node)

    # Build new schema
    new_parent = SchemaNode()
    new_parent.title_group = ja_node.title_group
    new_parent.key = ja_node.key
    ja_node.title_group = TitleGroup()
    ja_node.key = "default"
    ja_node.default = True

    # Rework the family tree
    new_parent.append(ja_node)
    parent.children[index_of_ja_node] = new_parent
    new_parent.parent = parent

    index.save(override_dependencies=True)
    library.rebuild()
    refresh_version_state(index.title)
    handle_dependant_indices(index.title)
Ejemplo n.º 5
0
def convert_simple_index_to_complex(index):
    """
    The target complex text will have a 'default' node.
    All refs to this text should remain good.
    :param index:
    :return:
    """
    from sefaria.model.schema import TitleGroup

    assert isinstance(index, Index)

    ja_node = index.nodes
    assert isinstance(ja_node, JaggedArrayNode)

    # Repair all version
    vs = [v for v in index.versionSet()]
    for v in vs:
        assert isinstance(v, Version)
        v.chapter = {"default": v.chapter}
        v.save(override_dependencies=True)

    # Build new schema
    new_parent = SchemaNode()
    new_parent.title_group = ja_node.title_group
    new_parent.key = ja_node.key
    ja_node.title_group = TitleGroup()
    ja_node.key = "default"
    ja_node.default = True

    # attach to index record
    new_parent.append(ja_node)
    index.nodes = new_parent

    index.save(override_dependencies=True)
    library.rebuild()
    refresh_version_state(index.title)

    handle_dependant_indices(index.title)