|
|
|
@ -9,10 +9,27 @@ from apps.quiz.serializers import QuizListSerializer |
|
|
|
class LessonSerializer(serializers.ModelSerializer): |
|
|
|
is_complated = serializers.SerializerMethodField() |
|
|
|
quizs = serializers.SerializerMethodField() |
|
|
|
permission = serializers.SerializerMethodField() |
|
|
|
|
|
|
|
class Meta: |
|
|
|
model = Lesson |
|
|
|
fields = ['id', 'title', 'priority', 'is_active', 'duration', 'content_type', 'content_file', 'video_link', 'is_complated', 'quizs'] |
|
|
|
fields = ['id', 'title', 'priority', 'is_active', 'permission','duration', 'content_type', 'content_file', 'video_link', 'is_complated', 'quizs'] |
|
|
|
|
|
|
|
def get_permission(self, obj): |
|
|
|
if student := self._get_authenticated_user(): |
|
|
|
if not self._is_participant(student, obj.course): |
|
|
|
return False |
|
|
|
return True |
|
|
|
return False |
|
|
|
|
|
|
|
def _get_authenticated_user(self): |
|
|
|
"""Helper method to retrieve the authenticated user from the context.""" |
|
|
|
request = self.context.get('request') |
|
|
|
return request.user if request and request.user.is_authenticated else None |
|
|
|
|
|
|
|
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() |
|
|
|
|
|
|
|
def get_is_complated(self, obj): |
|
|
|
request = self.context.get('request') |
|
|
|
|