diff --git a/futurex_openedx_extensions/dashboard/serializers.py b/futurex_openedx_extensions/dashboard/serializers.py index b27c3d2c..57a6be4d 100644 --- a/futurex_openedx_extensions/dashboard/serializers.py +++ b/futurex_openedx_extensions/dashboard/serializers.py @@ -15,7 +15,7 @@ class LearnerDetailsSerializer(serializers.ModelSerializer): username = serializers.CharField() email = serializers.EmailField() mobile_no = serializers.SerializerMethodField() - date_of_birth = serializers.SerializerMethodField() + year_of_birth = serializers.SerializerMethodField() gender = serializers.SerializerMethodField() date_joined = serializers.DateTimeField() last_login = serializers.DateTimeField() @@ -30,7 +30,7 @@ class Meta: 'username', 'email', 'mobile_no', - 'date_of_birth', + 'year_of_birth', 'gender', 'date_joined', 'last_login', @@ -55,10 +55,6 @@ def get_mobile_no(self, obj): """Return mobile number.""" return self._get_profile_field(obj, 'phone_number') - def get_date_of_birth(self, obj): # pylint: disable=unused-argument - """Return date of birth.""" - return None - def get_gender(self, obj): """Return gender.""" return self._get_profile_field(obj, 'gender') @@ -71,6 +67,10 @@ def get_enrolled_courses_count(self, obj): """Return enrolled courses count.""" return obj.courses_count + def get_year_of_birth(self, obj): + """Return year of birth.""" + return self._get_profile_field(obj, 'year_of_birth') + class CourseDetailsSerializer(serializers.ModelSerializer): """Serializer for course details.""" diff --git a/tests/test_dashboard/test_serializers.py b/tests/test_dashboard/test_serializers.py index 7649788f..93200072 100644 --- a/tests/test_dashboard/test_serializers.py +++ b/tests/test_dashboard/test_serializers.py @@ -24,7 +24,7 @@ def test_learner_details_serializer_no_profile(): assert data[0]['user_id'] == 10 assert data[0]['full_name'] is None assert data[0]['mobile_no'] is None - assert data[0]['date_of_birth'] is None + assert data[0]['year_of_birth'] is None assert data[0]['gender'] is None @@ -36,6 +36,7 @@ def test_learner_details_serializer_with_profile(): name='Test User', phone_number='1234567890', gender='m', + year_of_birth=1988, ) queryset = get_dummy_queryset() data = LearnerDetailsSerializer(queryset, many=True).data @@ -43,5 +44,5 @@ def test_learner_details_serializer_with_profile(): assert data[0]['user_id'] == 10 assert data[0]['full_name'] == 'Test User' assert data[0]['mobile_no'] == '1234567890' - assert data[0]['date_of_birth'] is None + assert data[0]['year_of_birth'] == 1988 assert data[0]['gender'] == 'm'