def update_summaries_on_change(ref, old_ref=None, recount=True): """ Update text summary docs to account for change or insertion of 'text' * recount - whether or not to perform a new count of available text """ index = sefaria.model.text.get_index(ref) indx_dict = index.contents() if recount: counts.update_text_count(ref) toc = get_toc() resort_other = False if indx_dict["categories"][0] != "Commentary": if indx_dict["categories"][0] not in order: indx_dict["categories"].insert(0, "Other") resort_other = True node = get_or_make_summary_node(toc, indx_dict["categories"]) text = add_counts_to_index(indx_dict) else: cats = indx_dict["categories"][1:2] + ["Commentary" ] + indx_dict["categories"][2:] node = get_or_make_summary_node(toc, cats) text = add_counts_to_index(indx_dict) found = False test_title = old_ref or text["title"] for item in node: if item.get("title") == test_title: item.update(text) found = True break if not found: node.append(text) node[:] = sort_toc_node(node) # If a new category may have been added to other, resort the cateogries if resort_other: toc[-1]["contents"] = sort_toc_node(toc[-1]["contents"]) save_toc(toc) save_toc_to_db()
def update_summaries_on_change(ref, old_ref=None, recount=True): """ Update text summary docs to account for change or insertion of 'text' * recount - whether or not to perform a new count of available text """ index = sefaria.model.text.get_index(ref) indx_dict = index.contents() if recount: counts.update_text_count(ref) toc = get_toc() resort_other = False if indx_dict["categories"][0] != "Commentary": if indx_dict["categories"][0] not in order: indx_dict["categories"].insert(0, "Other") resort_other = True node = get_or_make_summary_node(toc, indx_dict["categories"]) text = add_counts_to_index(indx_dict) else: cats = indx_dict["categories"][1:2] + ["Commentary"] + indx_dict["categories"][2:] node = get_or_make_summary_node(toc, cats) text = add_counts_to_index(indx_dict) found = False test_title = old_ref or text["title"] for item in node: if item.get("title") == test_title: item.update(text) found = True break if not found: node.append(text) node[:] = sort_toc_node(node) # If a new category may have been added to other, resort the cateogries if resort_other: toc[-1]["contents"] = sort_toc_node(toc[-1]["contents"]) save_toc(toc) save_toc_to_db()
def update_summaries_on_change(ref, old_ref=None, recount=True): """ Update text summary docs to account for change or insertion of 'text' * recount - whether or not to perform a new count of available text """ index = texts.get_index(ref) if "error" in index: return index if recount: counts.update_text_count(ref) resort_other = False if index["categories"][0] not in order: index["categories"].insert(0, "Other") resort_other = True toc = get_toc() node = get_or_make_summary_node(toc, index["categories"]) text = add_counts_to_index(index) found = False test_title = old_ref or text["title"] for item in node: if item.get("title") == test_title: item.update(text) found = True break if not found: node.append(text) node[:] = sort_toc_node(node) # If a new category may have been added to other, resort the cateogries if resort_other: toc[-1]["contents"] = sort_toc_node(toc[-1]["contents"]) save_toc(toc)
def add_counts_to_index(text): """ Returns a dictionary representing a text which includes index info, and text counts. """ count = db.counts.find_one({"title": text["title"]}) or \ counts.update_text_count(text["title"]) if not count: return text if count and "percentAvailable" in count: text["percentAvailable"] = count["percentAvailable"] text["availableCounts"] = counts.make_available_counts_dict(text, count) return text
def add_counts_to_index(indx_dict): """ Returns a dictionary representing a text which includes index info, and text counts. """ count = db.counts.find_one({"title": indx_dict["title"]}) or \ counts.update_text_count(indx_dict["title"]) if not count: return indx_dict if count and "percentAvailable" in count: indx_dict["percentAvailable"] = count["percentAvailable"] if count and "estimatedCompleteness" in count: indx_dict["isSparse"] = max(count["estimatedCompleteness"]['he']['isSparse'], count["estimatedCompleteness"]['en']['isSparse']) indx_dict["availableCounts"] = counts.make_available_counts_dict(indx_dict, count) return indx_dict
def add_counts_to_index(indx_dict): """ Returns a dictionary representing a text which includes index info, and text counts. """ count = db.counts.find_one({"title": indx_dict["title"]}) or \ counts.update_text_count(indx_dict["title"]) if not count: return indx_dict if count and "percentAvailable" in count: indx_dict["percentAvailable"] = count["percentAvailable"] if count and "estimatedCompleteness" in count: indx_dict["isSparse"] = max( count["estimatedCompleteness"]['he']['isSparse'], count["estimatedCompleteness"]['en']['isSparse']) indx_dict["availableCounts"] = counts.make_available_counts_dict( indx_dict, count) return indx_dict