feat: hook for course hasStarted attribute

This commit is contained in:
Muhammad Bilal Tahir
2023-07-19 18:46:37 +05:00
committed by jajjibhai008
parent 5acc4e58fa
commit 962e45196f

View File

@@ -10,6 +10,7 @@ from django.urls import reverse
from django.utils import timezone
from opaque_keys.edx.keys import CourseKey
from rest_framework import serializers
from openedx_filters.learning.filters import CourseEnrollmentAPIRenderStarted
from common.djangoapps.course_modes.models import CourseMode
from openedx.features.course_experience import course_home_url
@@ -244,6 +245,15 @@ class EnrollmentSerializer(serializers.Serializer):
def get_hasOptedOutOfEmail(self, enrollment):
return enrollment.course_id in self.context.get("course_optouts", [])
def to_representation(self, instance):
"""Serialize the enrollment instance to be able to update the values before the API finishes rendering."""
serialized_enrollment = super().to_representation(instance)
course_key, serialized_enrollment = CourseEnrollmentAPIRenderStarted().run_filter(
course_key=instance.course_id,
serialized_enrollment=serialized_enrollment,
)
return serialized_enrollment
class GradeDataSerializer(serializers.Serializer):
"""Info about grades for this enrollment"""