def test_add_delete_commentary_links_complex(): #test that there are the same number of links before and after title = 'Kos Shel Eliyahu on Pesach Haggadah' desired_link_count = 80 regex = Ref(title).regex() add_and_delete_invalid_commentary_links(Ref(title), 1) ls = LinkSet({"refs": {"$regex": regex}, "generated_by": "add_commentary_links"}) link_count = ls.count() assert desired_link_count == link_count
def test_add_delete_commentary_links(): #test that there are the same number of links before and after title = 'Rashi on Genesis' desired_link_count = 2027 regex = Ref(title).regex() add_and_delete_invalid_commentary_links(Ref(title), 1) ls = LinkSet({"refs": {"$regex": regex}, "generated_by": "add_commentary_links"}) link_count = ls.count() assert desired_link_count == link_count
def test_add_delete_commentary_links(): #test that there are the same number of links before and after title = 'Rashi on Genesis' regex = Ref(title).regex() desired_link_count = LinkSet({"refs": {"$regex": regex}, "auto": True, "generated_by": "add_commentary_links"}).count() add_and_delete_invalid_commentary_links(Ref(title), 1) ls = LinkSet({"refs": {"$regex": regex}, "generated_by": "add_commentary_links"}) link_count = ls.count() assert desired_link_count == link_count
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) if USE_VARNISH: invalidate_ref(oref, lang=lang, version=vtitle, purge=True) if oref.next_section_ref(): invalidate_ref(oref.next_section_ref(), lang=lang, version=vtitle, purge=True) if oref.prev_section_ref(): invalidate_ref(oref.prev_section_ref(), lang=lang, version=vtitle, purge=True) if not kwargs.get("skip_links", None): from sefaria.helper.link import add_and_delete_invalid_commentary_links, add_links_from_text # Commentaries generate links to their base text automatically if oref.type == "Commentary": add_and_delete_invalid_commentary_links(oref, user, **kwargs) # scan text for links to auto add add_links_from_text(oref, lang, chunk.text, chunk.full_version._id, user, **kwargs) if USE_VARNISH: invalidate_linked(oref) return chunk
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 model.user_profile.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) if USE_VARNISH: invalidate_ref(oref, lang=lang, version=vtitle, purge=True) if oref.next_section_ref(): invalidate_ref(oref.next_section_ref(), lang=lang, version=vtitle, purge=True) if oref.prev_section_ref(): invalidate_ref(oref.prev_section_ref(), lang=lang, version=vtitle, purge=True) if not kwargs.get("skip_links", None): from sefaria.helper.link import add_and_delete_invalid_commentary_links, add_links_from_text # Commentaries generate links to their base text automatically if oref.type == "Commentary": add_and_delete_invalid_commentary_links(oref, user, **kwargs) # scan text for links to auto add add_links_from_text(oref, lang, chunk.text, chunk.full_version._id, user, **kwargs) if USE_VARNISH: invalidate_linked(oref) return chunk