Skip to content

Commit

Permalink
Logic changed
Browse files Browse the repository at this point in the history
  • Loading branch information
krishna-ts authored Jul 11, 2024
1 parent abfb257 commit 04e48a6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
7 changes: 5 additions & 2 deletions common/djangoapps/student/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ def get_course_dates_for_email(user, course_id, request):
def get_assessments_for_courses(request):
user = User.objects.get(email = request.user.email)
user_courses = get_course_enrollments(user.username)
response_data = {"courses":[]}
response_data = {"courses":[], "sections":[]}
for i, user_course in enumerate(user_courses):
course_key_string = user_course["course_details"]["course_id"]
course_key = CourseKey.from_string(course_key_string)
Expand All @@ -948,10 +948,13 @@ def get_assessments_for_courses(request):

response_data["courses"].append({
'name':user_course["course_details"]["course_name"],
'section_scores':section_scores,
'date_blocks': new_blocks
})

response_data["sections"].appned({
'section_scores':section_scores,
})

# User locale settings
user_timezone_locale = user_timezone_locale_prefs(request)
response_data['user_timezone']=user_timezone_locale['user_timezone']
Expand Down
19 changes: 13 additions & 6 deletions lms/djangoapps/course_home_api/assessments/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,22 @@ def get_show_grades(self, subsection):
return subsection.show_grades(self.context['staff_access'])


merged_subsections = []

class SectionScoresSerializer(ReadOnlySerializer):
"""
Serializer for sections in section_scores
"""
subsections = SubsectionScoresSerializer(source='sections', many=True)
section_scores = SubsectionScoresSerializer(source='sections', many=True)

def to_representation(self, instance):
representation = super().to_representation(instance)

for course in representation['section_scores']:
merged_subsections.extend(course)

return representation


class AssessmentsSerializerDatesSummary(serializers.Serializer):
"""
Expand Down Expand Up @@ -108,17 +119,12 @@ class CourseSummary(serializers.Serializer):
Serializer for Assessmentes Objects.
"""
name = serializers.CharField()
section_scores = SectionScoresSerializer(many=True)
date_blocks = AssessmentsSerializerDatesSummary(many=True)

def to_representation(self, instance):
representation = super().to_representation(instance)
course_name = representation.pop('name') # Get and remove the course name
merged_subsections = []
for section in representation['section_scores']:
merged_subsections.extend(section['subsections'])

log.info(merged_subsections)
# Add course name to each date_block
start_date = ""
for date_block in representation['date_blocks']:
Expand All @@ -143,6 +149,7 @@ class AssessmentsSerializer(serializers.Serializer):
Serializer for the Dates Tab
"""
courses = CourseSummary(many=True)
sections = SectionScoresSerializer(many=True)
user_timezone = serializers.CharField(allow_null=True)

def to_representation(self, instance):
Expand Down

0 comments on commit 04e48a6

Please sign in to comment.