You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.0 KiB
39 lines
1.0 KiB
|
|
|
|
from rest_framework import serializers
|
|
from apps.course.models import Lesson, Participant, LessonCompletion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LessonSerializer(serializers.ModelSerializer):
|
|
is_complated = serializers.SerializerMethodField()
|
|
quiz = serializers.SerializerMethodField()
|
|
|
|
class Meta:
|
|
model = Lesson
|
|
fields = ['id', 'title', 'priority', 'is_active', 'duration', 'content_type', 'content_file', 'video_link', 'is_complated', 'quiz']
|
|
|
|
def get_is_complated(self, obj):
|
|
request = self.context.get('request')
|
|
if not request or not request.user.is_authenticated:
|
|
return False
|
|
user = request.user
|
|
is_participant = Participant.objects.filter(
|
|
student=user,
|
|
course=obj.course
|
|
).exists()
|
|
|
|
if not is_participant:
|
|
return False
|
|
|
|
return LessonCompletion.objects.filter(
|
|
student=user,
|
|
lesson=obj
|
|
).exists()
|
|
|
|
|
|
def get_quiz(self, obj):
|
|
return {}
|