Skip to content

Commit

Permalink
refactor: [AXM-288] Refactor get_course_assignments method
Browse files Browse the repository at this point in the history
  • Loading branch information
KyryloKireiev authored and monteri committed Apr 24, 2024
1 parent f53aff4 commit d12b0a5
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions lms/djangoapps/mobile_api/users/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,29 +267,28 @@ def get_course_assignments(self, model: CourseEnrollment) -> Dict[str, Optional[
self.context.get('request'),
include_past_dates=True
)
next_assignment_all = []
next_assignment = []
past_assignment = []
past_assignments = []
future_assignments = []

timezone = get_user_timezone_or_last_seen_timezone_or_utc(model.user)
for assignment in sorted(assignments, key=lambda x: x.date):
if assignment.date < datetime.now(timezone):
past_assignment.append(assignment)
past_assignments.append(assignment)
else:
if not assignment.complete:
next_assignment_all.append(assignment)
future_assignments.append(assignment)

if future_assignments:
future_assignment_date = future_assignments[0].date.date()
next_assignments = [
assignment for assignment in future_assignments if assignment.date.date() == future_assignment_date
]
else:
next_assignments = []
if future_assignments:
future_assignment_date = future_assignments[0].date.date()
next_assignments = [
assignment for assignment in future_assignments if assignment.date.date() == future_assignment_date
]
else:
next_assignments = []

return {
'future_assignments': DateSummarySerializer(next_assignment, many=True).data,
'past_assignments': DateSummarySerializer(past_assignment, many=True).data,
'future_assignments': DateSummarySerializer(next_assignments, many=True).data,
'past_assignments': DateSummarySerializer(past_assignments, many=True).data,
}

class Meta:
Expand Down

0 comments on commit d12b0a5

Please sign in to comment.