def modify_text(user, oref, vtitle, lang, text, vsource=None, **kwargs): """ Updates a chunk of text, identified by oref, versionTitle, and lang, and records history. :param user: :param oref: :param vtitle: :param lang: :param text: :param vsource: :return: """ chunk = model.TextChunk(oref, lang, vtitle) if getattr(chunk.version(), "status", "") == "locked" and not is_user_staff(user): raise InputError("This text has been locked against further edits.") action = kwargs.get("type") or "edit" if chunk.text else "add" old_text = chunk.text chunk.text = text if vsource: chunk.versionSource = vsource # todo: log this change if chunk.save(): model.log_text(user, action, oref, lang, vtitle, old_text, text, **kwargs) from sefaria.helper.link import add_commentary_links, add_links_from_text # Commentaries generate links to their base text automatically if oref.type == "Commentary": add_commentary_links(oref, user, **kwargs) # scan text for links to auto add add_links_from_text(oref.normal(), lang, chunk.text, chunk.full_version._id, user, **kwargs) return chunk
def test_add_commentary_links_default_node(): title = "Be'er Mayim Chaim on Chofetz Chaim" found = add_commentary_links(Ref(title), 1)
def test_add_commentary_links(): #test simple adding links title = 'Rashi on Genesis' desired_link_count = 2027 found = add_commentary_links(Ref(title), 1) assert len(found) == desired_link_count
def test_add_commentary_links_complex(): title = 'Kos Shel Eliyahu on Pesach Haggadah' desired_link_count = 80 found = add_commentary_links(Ref(title), 1) assert len(found) == desired_link_count
def test_add_commentary_links(): #test simple adding links title = 'Rashi on Genesis' desired_link_count = LinkSet({"refs": {"$regex": Ref(title).regex()},"auto": True, "generated_by": "add_commentary_links"}).count() found = add_commentary_links(Ref(title), 1) assert len(found) == desired_link_count