Exemplo n.º 1
0
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
	"""
	global toc
	toc = get_toc()
	index = sefaria.get_index(ref)
	if "error" in index:
		return index

	if recount:
		sefaria.update_text_count(ref)

	resort_other = False
	if index["categories"][0] not in order:
		index["categories"].insert(0, "Other")
		resort_other = True

	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)
Exemplo n.º 2
0
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
	"""
    global toc
    toc = get_toc()
    index = sefaria.get_index(ref)
    if "error" in index:
        return index

    if recount:
        sefaria.update_text_count(ref)

    resort_other = False
    if index["categories"][0] not in order:
        index["categories"].insert(0, "Other")
        resort_other = True

    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)
Exemplo n.º 3
0
def add_counts_to_index(text):
	"""
	Returns a dictionary representing a text which includes index info,
	and text counts.
	"""
	count = sefaria.db.counts.find_one({"title": text["title"]}) or \
			 sefaria.update_text_count(text["title"])
	if not count:
		return text

	if count and "percentAvailable" in count:
		text["percentAvailable"] = count["percentAvailable"]

	text["availableCounts"] = make_available_counts_dict(text, count)

	return text
Exemplo n.º 4
0
def add_counts_to_index(text):
    """
	Returns a dictionary representing a text which includes index info,
	and text counts.
	"""
    count = sefaria.db.counts.find_one({"title": text["title"]}) or \
       sefaria.update_text_count(text["title"])
    if not count:
        return text

    if count and "percentAvailable" in count:
        text["percentAvailable"] = count["percentAvailable"]

    text["availableCounts"] = make_available_counts_dict(text, count)

    return text