def make_rt_link(a, tref): l = RefTopicLink({ 'toTopic': a, 'ref': tref, 'linkType': 'about', 'dataSource': 'sefaria' }) l.save() return l
def test_duplicate(self, topic_graph): from sefaria.system.exceptions import DuplicateRecordError attrs = { 'ref': 'Genesis 1:1', 'toTopic': '6', 'linkType': 'about', 'dataSource': 'sefaria' } l1 = RefTopicLink(attrs) l1.save() l2 = RefTopicLink(attrs) with pytest.raises(DuplicateRecordError): l2.save() l1.delete()
def update_sheet_topic_links(sheet_id, new_topics, old_topics): """ Adds and removes sheet topic links per differences in old and new topics list. Only adds link for public sheets. """ topic_diff = topic_list_diff(old_topics, new_topics) for removed in topic_diff["removed"]: #print("removing {}".format(removed[1])) RefTopicLinkSet( { "class": "refTopic", "toTopic": removed[1], "expandedRefs": "Sheet {}".format(sheet_id), "linkType": "about", "is_sheet": True, "dataSource": "sefaria-users" }, hint="expandedRefs_1").delete() status = db.sheets.find_one({ "id": sheet_id }, { "status": 1 }).get("status", "unlisted") if status != "public": return for added in topic_diff["added"]: #print("adding {}".format(added[1])) attrs = { "class": "refTopic", "toTopic": added[1], "ref": "Sheet {}".format(sheet_id), "expandedRefs": ["Sheet {}".format(sheet_id)], "linkType": "about", "is_sheet": True, "dataSource": "sefaria-users" } tl = RefTopicLink(attrs) try: tl.save() except DuplicateRecordError: pass
def test_add_expanded_refs(self, topic_graph): attrs = { 'ref': 'Genesis 1:1', 'toTopic': '6', 'linkType': 'about', 'dataSource': 'sefaria' } l = RefTopicLink(attrs) l.save() assert getattr(l, 'class') == 'refTopic' assert l.expandedRefs == ['Genesis 1:1'] l.delete() attrs = { 'ref': 'Genesis 1:1-3', 'toTopic': '6', 'linkType': 'about', 'dataSource': 'sefaria' } l = RefTopicLink(attrs) l.save() assert l.expandedRefs == ['Genesis 1:1', 'Genesis 1:2', 'Genesis 1:3'] l.delete() attrs = { 'ref': 'Genesis 1-2', 'toTopic': '6', 'linkType': 'about', 'dataSource': 'sefaria' } l = RefTopicLink(attrs) l.save() test_refs = [r.normal() for r in Ref('Genesis 1-2').all_segment_refs()] assert l.expandedRefs == test_refs l.delete()