示例#1
0
    def test_merge(self, topic_graph_to_merge):
        ts = topic_graph_to_merge['topics']
        ts['20'].merge(ts['40'])

        t20 = Topic.init('20')
        assert t20.slug == '20'
        assert len(t20.titles) == 2
        assert t20.get_primary_title('en') == '20'
        ls = t20.link_set(_class='intraTopic')
        assert {l.topic for l in ls} == {'10', '30', '50'}

        s = db.sheets.find_one({"id": 1234567890})
        assert s['topics'] == [{
            "slug": '20',
            'asTyped': 'twenty'
        }, {
            "slug": '20',
            'asTyped': '4d'
        }, {
            "slug": '20',
            'asTyped': 'twent-e'
        }, {
            "slug": '30',
            'asTyped': 'thirty'
        }]
示例#2
0
    def generate_parasha_topics_story(cls, parasha_obj, mustHave, iteration, k,
                                      **kwargs):
        from sefaria.utils.calendars import make_parashah_response_from_calendar_entry
        from sefaria.helper.topic import get_topic_by_parasha
        from sefaria.model.topic import Topic
        page = iteration - 1
        topic = get_topic_by_parasha(parasha_obj["parasha"])
        if not topic:
            return
        link_set = topic.link_set(_class='intraTopic', page=page, limit=k)
        related_topics = list(
            filter(None, [Topic.init(l.topic) for l in link_set]))
        if len(related_topics) < k:
            return

        cal = make_parashah_response_from_calendar_entry(parasha_obj)[0]

        return cls.generate_story(topics=related_topics,
                                  title={
                                      "en":
                                      "Topics in " + cal["displayValue"]["en"],
                                      "he":
                                      "נושאים ב" + cal["displayValue"]["he"]
                                  },
                                  lead={
                                      "en": "Weekly Torah Portion",
                                      "he": 'פרשת השבוע'
                                  },
                                  mustHave=mustHave or [],
                                  **kwargs)