Example #1
0
def learn_page(request, set_name):
    set_ = Set.objects.get(name__exact=set_name)
    if request.method == "POST":
        q_idx = int(request.POST.get("q_idx"))
        phrase = Phrase.objects.filter(set_id=set_.id).order_by("pk").filter(id__gt=q_idx)[0]
        player_record = PlayerRecord()
        player_record.phrase = phrase
        player_record.answer = request.POST.get("user_text", "")
        player_record.save()
    else:
        phrase = Phrase.objects.filter(set=set_).order_by("pk")[0]

    next_phrase = Phrase.objects.filter(set_id=set_.id).order_by("pk").filter(id__gt=phrase.id)
    has_next_phrase = False if len(next_phrase) == 0 else True

    response = render(
        request,
        "learn.html",
        {
            "set_name": set_.name,
            "set_description": set_.description,
            "quiz": phrase.korean,
            "answer": phrase.english,
            "q_idx": phrase.id,
            "has_next_phrase": has_next_phrase,
        },
    )
    return response
Example #2
0
def learn_page(request, set_name):
    set_ = Set.objects.get(name__exact=set_name)
    if request.method == 'POST':
        q_idx = int(request.POST.get('q_idx'))
        phrase = Phrase.objects.filter(set_id=set_.id).\
            order_by('pk').filter(id__gt=q_idx)[0]
        player_record = PlayerRecord()
        player_record.phrase = phrase
        player_record.answer = request.POST.get('user_text', '')
        player_record.save()
    else:
        phrase = Phrase.objects.filter(set=set_).order_by('pk')[0]

    next_phrase = Phrase.objects.filter(set_id=set_.id).\
        order_by('pk').filter(id__gt=phrase.id)
    has_next_phrase = False if len(next_phrase) == 0 else True

    response = render(request, 'learn.html', {
        'set': set_,
        'quiz': phrase.korean,
        'answer': phrase.english,
        'q_idx': phrase.id,
        'has_next_phrase': has_next_phrase
        })
    return response
Example #3
0
def learn_page(request, set_name):
    set_ = Set.objects.get(name__exact=set_name)
    if request.method == 'POST':
        q_idx = int(request.POST.get('q_idx'))
        phrase = Phrase.objects.filter(set_id=set_.id).\
            order_by('pk').filter(id__gt=q_idx)[0]
        player_record = PlayerRecord()
        player_record.phrase = phrase
        player_record.answer = request.POST.get('user_text', '')
        player_record.save()
    else:
        phrase = Phrase.objects.filter(set=set_).order_by('pk')[0]

    next_phrase = Phrase.objects.filter(set_id=set_.id).\
        order_by('pk').filter(id__gt=phrase.id)
    has_next_phrase = False if len(next_phrase) == 0 else True

    response = render(request, 'learn.html', {
        'set_name': set_.name,
        'set_description': set_.description,
        'quiz': phrase.korean,
        'answer': phrase.english,
        'q_idx': phrase.id,
        'has_next_phrase': has_next_phrase
        })
    return response
Example #4
0
    def test_saving_and_retreiving_player_record(self):
        qna_set = Set()
        qna_set.name = "QnA"
        qna_set.save()

        phrase = Phrase()
        phrase.url = "http://www.stackoverflow.com"
        phrase.english = "I have a question"
        phrase.korean = "질문이 있어요"
        phrase.set = qna_set
        phrase.save()

        player_record = PlayerRecord()
        player_record.phrase = phrase
        player_record.answer = "I have question"
        player_record.save()

        saved_player_records = PlayerRecord.objects.all()
        self.assertEqual(saved_player_records.count(), 1)

        saved_player_record = saved_player_records[0]

        self.assertEqual(saved_player_record.answer, "I have question")
Example #5
0
    def test_saving_and_retreiving_player_record(self):
        qna_set = Set()
        qna_set.name = "QnA"
        qna_set.save()

        phrase = Phrase()
        phrase.url = "http://www.stackoverflow.com"
        phrase.english = "I have a question"
        phrase.korean = "질문이 있어요"
        phrase.set = qna_set
        phrase.save()

        player_record = PlayerRecord()
        player_record.phrase = phrase
        player_record.answer = "I have question"
        player_record.save()

        saved_player_records = PlayerRecord.objects.all()
        self.assertEqual(saved_player_records.count(), 1)

        saved_player_record = saved_player_records[0]

        self.assertEqual(saved_player_record.answer, "I have question")