def test_all_index_caches_removed_and_added_simple(self): assert "Genesis" in library._index_map assert "Bereishit" in library._index_title_maps["en"]["Genesis"] assert "Bereishit" in library._title_node_maps["en"] assert "Bereishit" in library._title_node_with_commentary_maps["en"] assert u"בראשית" in library._index_title_maps["he"]["Genesis"] assert u"בראשית" in library._title_node_maps["he"] assert u"בראשית" in library._title_node_with_commentary_maps["he"] library.remove_index_record_from_cache(library.get_index("Genesis")) assert "Genesis" not in library._index_map assert "Genesis" not in library._index_title_maps["en"] assert "Bereishit" not in library._title_node_maps["en"] assert "Bereishit" not in library._title_node_with_commentary_maps[ "en"] assert "Genesis" not in library._index_title_maps["he"] assert u"בראשית" not in library._title_node_maps["he"] assert u"בראשית" not in library._title_node_with_commentary_maps["he"] library.add_index_record_to_cache(Index().load({"title": "Genesis"})) assert "Genesis" in library._index_map assert "Bereishit" in library._index_title_maps["en"]["Genesis"] assert "Bereishit" in library._title_node_maps["en"] assert "Bereishit" in library._title_node_with_commentary_maps["en"] assert u"בראשית" in library._index_title_maps["he"]["Genesis"] assert u"בראשית" in library._title_node_maps["he"] assert u"בראשית" in library._title_node_with_commentary_maps["he"]
def test_all_index_caches_removed_and_added_simple(self): assert "Genesis" in library._index_map assert "Bereishit" in library._index_title_maps["en"]["Genesis"] assert "Bereishit" in library._title_node_maps["en"] assert "Bereishit" in library._title_node_with_commentary_maps["en"] assert u"בראשית" in library._index_title_maps["he"]["Genesis"] assert u"בראשית" in library._title_node_maps["he"] assert u"בראשית" in library._title_node_with_commentary_maps["he"] library.remove_index_record_from_cache(library.get_index("Genesis")) assert "Genesis" not in library._index_map assert "Genesis" not in library._index_title_maps["en"] assert "Bereishit" not in library._title_node_maps["en"] assert "Bereishit" not in library._title_node_with_commentary_maps["en"] assert "Genesis" not in library._index_title_maps["he"] assert u"בראשית" not in library._title_node_maps["he"] assert u"בראשית" not in library._title_node_with_commentary_maps["he"] library.add_index_record_to_cache(Index().load({"title": "Genesis"})) assert "Genesis" in library._index_map assert "Bereishit" in library._index_title_maps["en"]["Genesis"] assert "Bereishit" in library._title_node_maps["en"] assert "Bereishit" in library._title_node_with_commentary_maps["en"] assert u"בראשית" in library._index_title_maps["he"]["Genesis"] assert u"בראשית" in library._title_node_maps["he"] assert u"בראשית" in library._title_node_with_commentary_maps["he"]
def test_all_index_caches_removed_and_added_commentary(self): assert "Rashi on Genesis" in library._index_map assert "Rashi on Bereishit" in library._title_node_with_commentary_maps[ "en"] assert "Rashi on Bereishit" in library._index_title_commentary_maps[ "en"]["Rashi on Genesis"] assert u'רש"י על בראשית' in library._index_title_commentary_maps["he"][ "Rashi on Genesis"] assert u'רש"י על בראשית' in library._title_node_with_commentary_maps[ "he"] library.remove_index_record_from_cache( library.get_index("Rashi on Genesis")) assert "Rashi on Genesis" not in library._index_map assert "Rashi on Bereishit" not in library._title_node_with_commentary_maps[ "en"] assert "Rashi on Genesis" not in library._index_title_commentary_maps[ "en"] assert "Rashi on Genesis" not in library._index_title_commentary_maps[ "he"] assert u'רש"י על בראשית' not in library._title_node_with_commentary_maps[ "he"] library.add_index_record_to_cache(CommentaryIndex("Rashi", "Genesis")) assert "Rashi on Genesis" in library._index_map assert "Rashi on Bereishit" in library._title_node_with_commentary_maps[ "en"] assert "Rashi on Bereishit" in library._index_title_commentary_maps[ "en"]["Rashi on Genesis"] assert u'רש"י על בראשית' in library._index_title_commentary_maps["he"][ "Rashi on Genesis"] assert u'רש"י על בראשית' in library._title_node_with_commentary_maps[ "he"]
def text_toc_link(indx): """ Return an <a> tag linking to the text TOC for the Index """ from sefaria.model.text import library, AbstractIndex if not isinstance(indx, AbstractIndex): indx = library.get_index(indx) en = indx.nodes.primary_title("en") if not indx.is_commentary() else indx.title he = indx.nodes.primary_title("he") if not indx.is_commentary() else indx.heTitle link = u'<a href="/{}"><span class="int-en">{}</span><span class="int-he">{}</span></a>'.format(indx.title, en, he) return mark_safe(link)
def text_toc_link(indx): """ Return an <a> tag linking to the text TOC for the Index """ from sefaria.model.text import library, AbstractIndex if not isinstance(indx, AbstractIndex): indx = library.get_index(indx) en = indx.nodes.primary_title("en") he = indx.nodes.primary_title("he") link = u'<a href="/{}"><span class="int-en">{}</span><span class="int-he">{}</span></a>'.format(indx.title, en, he) return mark_safe(link)
def test_all_index_caches_removed_and_added_commentary(self): assert "Rashi on Genesis" in library._index_map assert "Rashi on Bereishit" in library._title_node_with_commentary_maps["en"] assert "Rashi on Bereishit" in library._index_title_commentary_maps["en"]["Rashi on Genesis"] assert u'רש"י על בראשית' in library._index_title_commentary_maps["he"]["Rashi on Genesis"] assert u'רש"י על בראשית' in library._title_node_with_commentary_maps["he"] library.remove_index_record_from_cache(library.get_index("Rashi on Genesis")) assert "Rashi on Genesis" not in library._index_map assert "Rashi on Bereishit" not in library._title_node_with_commentary_maps["en"] assert "Rashi on Genesis" not in library._index_title_commentary_maps["en"] assert "Rashi on Genesis" not in library._index_title_commentary_maps["he"] assert u'רש"י על בראשית' not in library._title_node_with_commentary_maps["he"] library.add_index_record_to_cache(CommentaryIndex("Rashi", "Genesis")) assert "Rashi on Genesis" in library._index_map assert "Rashi on Bereishit" in library._title_node_with_commentary_maps["en"] assert "Rashi on Bereishit" in library._index_title_commentary_maps["en"]["Rashi on Genesis"] assert u'רש"י על בראשית' in library._index_title_commentary_maps["he"]["Rashi on Genesis"] assert u'רש"י על בראשית' in library._title_node_with_commentary_maps["he"]
def _validate(self): from sefaria.model.text import library, Version if self.type == "index": assert self.content.get("index") assert library.get_index(self.content.get("index")) elif self.type == "version": i = self.content.get("index") v = self.content.get("version") l = self.content.get("language") assert i and v and l version = Version().load({ "title": i, "versionTitle": v, "language": l, }) assert version, "No Version Found: {}/{}/{}".format(i, v, l) elif self.type == "general": assert self.content.get("en"), "Please provide an English message." assert self.content.get("he"), "Please provide a Hebrew message." else: raise InputError("Unknown type for GlobalNotification: {}".format(self.type))
def _validate(self): from sefaria.model.text import library, Version if self.type == "index": assert self.content.get("index") assert library.get_index(self.content.get("index")) elif self.type == "version": i = self.content.get("index") v = self.content.get("version") l = self.content.get("language") assert i assert v assert l version = Version().load({ "title": i, "versionTitle": v, "language": l, }) assert version, "No Version Found: {}/{}/{}".format(i, v, l) elif self.type == "general": assert self.content.get("en"), "Please provide an English message." assert self.content.get("he"), "Please provide a Hebrew message." else: raise InputError(u"Unknown type for GlobalNotification: {}".format(self.type))
def _normalize(self): from sefaria.model.text import library if self.type == "index" or self.type == "version": i = library.get_index(self.content.get("index")) self.content["index"] = i.title
if base_ref is None or mei_ref is None: missed.append(mei_ref) continue else: self.stored_links.append( (base_ref.normal(), mei_ref.normal())) print 'stored {} links, missed {}'.format(len(self.stored_links), len(missed)) for i in missed: print i def post_links(self): links = [{ 'refs': [l[0], l[1]], 'type': 'commentary', 'auto': True, 'generated_by': 'Mei HaShiloach linker' } for l in self.stored_links] post_link(links) mei = library.get_index('Mei HaShiloach') nodes_to_link = mei.nodes.children[0].children[1:9] nodes_to_link.extend(mei.nodes.children[1].children[1:9]) nodes_to_link.extend(mei.nodes.children[2].children[0:8]) linker = MeiLinks() for i in nodes_to_link: linker.get_refs(i) linker.match_all(verbose=False) linker.post_links()