Exemplo n.º 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)
Exemplo n.º 2
0
    def perform_create(self, serializer):

        serializer.save()

        quiz_answers = serializer.instance
        quiz = quiz_answers[0].quiz

        quiz.completed = timezone.now()
        quiz.save()

        for quiz_card in quiz.quiz_cards.all():

            meaning_models = quiz_card.card.meanings.all()
            answer_models = quiz_card.quiz_answers.all()

            card_is_correct = len(meaning_models) == len(answer_models)
            meaning_texts = set(meaning.text.lower() for meaning in meaning_models)

            for quizAnswer in quiz_card.quiz_answers.all():

                if quizAnswer.text in meaning_texts:
                    quizAnswer.is_correct = True
                else:
                    quizAnswer.is_correct = False
                    card_is_correct = False

                quizAnswer.save()

            if card_is_correct and quiz_card.card.isToStudy():
                # todo move to somewhere like model.create
                is_learned = CardIsLearned()
                is_learned.user = self.request.user
                is_learned.card = quiz_card.card
                is_learned.save()

            if not card_is_correct and quiz_card.card.isLearned():
                to_study = CardToStudy()
                to_study.user = self.request.user
                to_study.card = quiz_card.card
                to_study.save()
Exemplo n.º 3
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()
Exemplo n.º 4
0
 def createCardToStudy(self, user, card):
     toStudy = CardToStudy()
     toStudy.card = card
     toStudy.user = user
     toStudy.save()
     return toStudy