|
|
@ -23,7 +23,14 @@ class QuizListSerializer(serializers.ModelSerializer): |
|
|
return False |
|
|
return False |
|
|
# Check if the user has participated in this quiz |
|
|
# Check if the user has participated in this quiz |
|
|
user = request.user |
|
|
user = request.user |
|
|
course = obj.lesson.course |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Get the course through CourseLesson model |
|
|
|
|
|
from apps.course.models.lesson import CourseLesson |
|
|
|
|
|
course_lesson = CourseLesson.objects.filter(lesson=obj.lesson).first() |
|
|
|
|
|
if not course_lesson: |
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
course = course_lesson.course |
|
|
|
|
|
|
|
|
if not self._is_participant(user, course): |
|
|
if not self._is_participant(user, course): |
|
|
return False |
|
|
return False |
|
|
@ -78,5 +85,19 @@ class QuizSerializer(serializers.ModelSerializer): |
|
|
return False |
|
|
return False |
|
|
# Check if the user has participated in this quiz |
|
|
# Check if the user has participated in this quiz |
|
|
user = request.user |
|
|
user = request.user |
|
|
|
|
|
|
|
|
|
|
|
# Get the course through CourseLesson model |
|
|
|
|
|
from apps.course.models.lesson import CourseLesson |
|
|
|
|
|
course_lesson = CourseLesson.objects.filter(lesson=obj.lesson).first() |
|
|
|
|
|
if not course_lesson: |
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
course = course_lesson.course |
|
|
|
|
|
|
|
|
|
|
|
# Check if user is a participant in the course |
|
|
|
|
|
from apps.course.models import Participant |
|
|
|
|
|
if not Participant.objects.filter(student=user, course=course).exists(): |
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
participated = QuizParticipant.objects.filter(user=user, quiz=obj).exists() |
|
|
participated = QuizParticipant.objects.filter(user=user, quiz=obj).exists() |
|
|
return not participated |
|
|
return not participated |