Пример #1
0
def process_index_delete_in_summaries(index, **kwargs):
    import sefaria.summaries as summaries
    if index.is_commentary():
        #deleting a commentary might cause a big shift in the ToC, so just rebuild for now.
        summaries.update_table_of_contents()
        return
    summaries.update_summaries_on_delete(index.title)
Пример #2
0
def process_index_delete_in_summaries(index, **kwargs):
    import sefaria.summaries as summaries
    if index.is_commentary():
        #deleting a commentary might cause a big shift in the ToC, so just rebuild for now.
        summaries.update_table_of_contents()
        return
    summaries.update_summaries_on_delete(index.title)
Пример #3
0
def update_summaries_on_index_save(index, **kwargs):
    import sefaria.summaries as summaries
    if index.is_commentary():
        #just redo the whole thing.
        summaries.update_table_of_contents()
        return
    old_values = kwargs.get('orig_vals')
    if 'title' in old_values:
        old_title = old_values['title']
    else:
        old_title = None
    summaries.update_summaries_on_change(index.title, old_title, False)
Пример #4
0
def update_summaries_on_index_save(index, **kwargs):
    import sefaria.summaries as summaries
    if index.is_commentary():
        #just redo the whole thing.
        summaries.update_table_of_contents()
        return
    old_values = kwargs.get('orig_vals')
    if 'title' in old_values:
        old_title = old_values['title']
    else:
        old_title = None
    summaries.update_summaries_on_change(index.title, old_title, False)
Пример #5
0
    def test_compare_db_toc_and_derived_toc(self):
        derived_toc = s.update_table_of_contents()
        base_json = json.dumps(derived_toc, sort_keys=True)
        oo_toc = library.get_toc_tree()
        serialized_oo_toc = oo_toc.get_root().serialize()["contents"]

        # Deep test of toc lists
        result = DeepDiff(derived_toc, serialized_oo_toc)
        assert not result or all(["JPS" in j["new_value"] for i in result.values() for j in i.values()])

        if result:
            # Irrelevant difference, but it makes the test below impossible.
            return

        # Check that the json is identical -
        # that the round-trip didn't change anything by reference that would poison the deep test
        new_json = json.dumps(serialized_oo_toc, sort_keys=True)
        assert len(base_json) == len(new_json)
Пример #6
0
    def test_compare_db_toc_and_derived_toc(self):
        derived_toc = s.update_table_of_contents()
        base_json = json.dumps(derived_toc, sort_keys=True)
        oo_toc = library.get_toc_tree()
        serialized_oo_toc = oo_toc.get_root().serialize()["contents"]

        # Deep test of toc lists
        result = DeepDiff(derived_toc, serialized_oo_toc)
        assert not result or all([
            "JPS" in j["new_value"] for i in list(result.values())
            for j in list(i.values())
        ])

        if result:
            # Irrelevant difference, but it makes the test below impossible.
            return

        # Check that the json is identical -
        # that the round-trip didn't change anything by reference that would poison the deep test
        new_json = json.dumps(serialized_oo_toc, sort_keys=True)
        assert len(base_json) == len(new_json)
Пример #7
0
import pytest
import sefaria.summaries as s
import sefaria.model as model
import sefaria.system.cache as scache
from sefaria.utils.testing_utils import *

#create, update, delete, change categories
# test that old title goes away on index title change (regular + commentary)
# test that no commentator is added
# no wandering commentaries


""" SOME SETUP """

text_titles = model.VersionSet({}).distinct('title')
s.update_table_of_contents()
scache.delete_cache_elem('toc_cache')


""" THE TESTS """


class Test_Toc(object):
    def test_toc_integrity(self):
        toc = s.get_toc()
        self.recur_toc_integrity(toc)


    def recur_toc_integrity(self, toc, depth=0):
         for toc_elem in toc:
            if 'category' in toc_elem:
Пример #8
0
import pytest
import sefaria.summaries as s
import sefaria.model as model
import sefaria.system.cache as scache
from sefaria.utils.testing_utils import *

#create, update, delete, change categories
# test that old title goes away on index title change (regular + commentary)
# test that no commentator is added
# no wandering commentaries


""" SOME SETUP """

text_titles = model.VersionSet({}).distinct('title')
s.update_table_of_contents()
scache.delete_cache_elem('toc_cache')


""" THE TESTS """


class Test_Toc(object):
    def test_toc_integrity(self):
        toc = s.get_toc()
        self.recur_toc_integrity(toc)


    def recur_toc_integrity(self, toc, depth=0):
         for toc_elem in toc:
            if 'category' in toc_elem:
    Modifies contents in place.
    :param treenode:
    :param callback:
    :param order:
    :param kwargs:
    :return:
    """
    if treenode.children:
        for i, node in enumerate(treenode.children):
            visit_structure(node, callback, i, **kwargs)
        if order is not None:  # skip root
            callback(treenode, **kwargs)


def create_category(treenode):
    c = Category()
    if Term().load({"name": treenode.primary_title("en")}):
        c.add_shared_term(treenode.primary_title("en"))
    else:
        c.add_primary_titles(treenode.primary_title("en"),
                             treenode.primary_title("he"))
    c.path = treenode.full_path
    c.lastPath = treenode.full_path[-1]
    print("Creating - {}".format(" / ".join(c.path)))
    c.save(override_dependencies=True)


db.category.remove({})
serial_toc = update_table_of_contents()
toctree = toc_serial_to_objects(serial_toc)
visit_structure(toctree, create_category)
    Tree visitor for traversing existing structure nodes of content trees and passing them to callback.
    Traverses from bottom up, with intention that this be used to aggregate content from content nodes up.
    Modifies contents in place.
    :param treenode:
    :param callback:
    :param order:
    :param kwargs:
    :return:
    """
    if treenode.children:
        for i, node in enumerate(treenode.children):
            visit_structure(node, callback, i, **kwargs)
        if order is not None:  # skip root
            callback(treenode, **kwargs)


def create_category(treenode):
    c = Category()
    if Term().load({"name": treenode.primary_title("en")}):
        c.add_shared_term(treenode.primary_title("en"))
    else:
        c.add_primary_titles(treenode.primary_title("en"), treenode.primary_title("he"))
    c.path = treenode.full_path
    c.lastPath = treenode.full_path[-1]
    print "Creating - {}".format(" / ".join(c.path))
    c.save(override_dependencies=True)

db.category.remove({})
serial_toc = update_table_of_contents()
toctree = toc_serial_to_objects(serial_toc)
visit_structure(toctree, create_category)