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)
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()
def createCard(self, user, text): card = Card() card.user = user card.text = text card.save() return card