示例#1
0
    def testCardToStudyIsDeletedWhenCardIsLearnedIsCreated(self):
        card = Card()
        card.user = self.user
        card.text = 'hello'
        card.save()

        to_study = CardToStudy()
        to_study.user = self.user
        to_study.card = card
        to_study.save()

        is_learned = CardIsLearned()
        is_learned.user = self.user
        is_learned.card = card
        is_learned.save()

        to_study = CardToStudy().find_by_user_and_card(self.user, card)
        self.assertIsNone(to_study)
示例#2
0
def addToLearning(sender, instance, **kwargs):
    history = instance
    card = Card().findByUserAndText(history.user, history.string)
    if history.count >= WARN_LEVEL_5:
        if card is None:
            card = Card()
            card.text = history.string
            card.user = history.user
            card.save()
            profile = UserProfile().findByUser(card.user)
            meanings = get_flat_meanings(card.text, profile.target_lang)
            for meaning in meanings:
                cardMeaning = CardMeaning()
                cardMeaning.text = meaning
                cardMeaning.card = card
                cardMeaning.user = card.user
                cardMeaning.save()
        try:
            card.to_study
        except CardToStudy.DoesNotExist:
            cardToStudy = CardToStudy()
            cardToStudy.card = card
            cardToStudy.user = card.user
            cardToStudy.save()
示例#3
0
 def createCard(self, user, text):
     card = Card()
     card.user = user
     card.text = text
     card.save()
     return card