Skip to content

Commit

Permalink
fix: TypeError: Object of type ZeroCourseGrade is not JSON serializable
Browse files Browse the repository at this point in the history
ensure Grade is read as JSON
  • Loading branch information
OmarIthawi committed May 27, 2024
1 parent 01a4d2d commit 68981d5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
9 changes: 6 additions & 3 deletions futurex_openedx_extensions/dashboard/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,15 @@ def get_progress(self, obj): # pylint: disable=no-self-use
return get_course_blocks_completion_summary(obj.id, user)

def get_grade(self, obj): # pylint: disable=no-self-use
"""Return the certificate URL."""
"""Return the grade summary."""
collected_block_structure = get_block_structure_manager(obj.id).get_collected()
course_grade = CourseGradeFactory().read(
get_user_model().objects.get(id=obj.related_user_id),
collected_block_structure=collected_block_structure
)
course_grade.update(visible_grades_only=True, has_staff_access=False)

return course_grade
return {
'percent': course_grade.percent,
'letter_grade': course_grade.letter_grade,
'is_passing': course_grade.passed,
}
15 changes: 8 additions & 7 deletions test_utils/edx_platform_mocks/fake_models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,15 @@ class CourseGradeFactory: # pylint: disable=too-few-public-methods
"""Mock"""
def read(self, *args, **kwargs): # pylint: disable=no-self-use
"""Mock read"""
class Dummy:
"""dummy class"""
class DummyGrade:
"""dummy grade class"""

letter_grade = "Fail"
percent = 0.4
passed = False

def update(self, *args, **kwargs): # pylint: disable=no-self-use
"""update"""
return None

def __iter__(self):
"""__iter__"""
return iter([("letter_grade", "Fail"), ("percent", 0.4), ("is_passing", False)])

return Dummy()
return DummyGrade()

0 comments on commit 68981d5

Please sign in to comment.