All checks were successful
Deploy Quartz site to GitHub Pages / build (push) Successful in 2m29s
29 lines
962 B
Python
29 lines
962 B
Python
from django.shortcuts import get_object_or_404
|
|
from django.http import HttpResponse
|
|
from django.views.decorators.http import require_http_methods
|
|
from quiz.models import QuizSession, QuizResult
|
|
|
|
|
|
@require_http_methods(["POST"])
|
|
def submit_difficulty(request, session_id):
|
|
"""Record difficulty rating for FSRS"""
|
|
session = get_object_or_404(QuizSession, id=session_id, user=request.quiz_user)
|
|
question_id = request.POST.get('question_id')
|
|
difficulty = request.POST.get('difficulty')
|
|
|
|
if not question_id or not difficulty:
|
|
return HttpResponse("Invalid submission", status=400)
|
|
|
|
try:
|
|
result = QuizResult.objects.get(
|
|
user=request.quiz_user,
|
|
quiz_session=session,
|
|
question_id=question_id
|
|
)
|
|
result.difficulty = difficulty
|
|
result.save()
|
|
return HttpResponse("OK")
|
|
except QuizResult.DoesNotExist:
|
|
return HttpResponse("Result not found", status=404)
|
|
|