|
|
|
@ -1,7 +1,7 @@ |
|
|
|
from rest_framework import serializers |
|
|
|
|
|
|
|
from apps.quiz.models import Question, Quiz, QuizParticipant |
|
|
|
from apps.course.models import Lesson |
|
|
|
from apps.course.models import Lesson, Participant |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -22,10 +22,19 @@ class QuizListSerializer(serializers.ModelSerializer): |
|
|
|
return False |
|
|
|
# Check if the user has participated in this quiz |
|
|
|
user = request.user |
|
|
|
course = obj.lesson.course |
|
|
|
|
|
|
|
if not self._is_participant(user, course): |
|
|
|
return False |
|
|
|
|
|
|
|
participated = QuizParticipant.objects.filter(user=user, quiz=obj).exists() |
|
|
|
return not participated |
|
|
|
|
|
|
|
|
|
|
|
def _is_participant(self, student, course): |
|
|
|
"""Helper method to check if a student is a participant in the given course.""" |
|
|
|
return Participant.objects.filter(student=student, course=course).exists() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|