Skip to content

Commit

Permalink
If cohort info throws exception send modified response
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebrownlee committed Oct 16, 2023
1 parent 50ad63c commit 4bd4fc2
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions LearningAPI/models/people/nssuser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""NssUser database model"""
import statistics
import datetime
import logging

from django.db import models
from django.conf import settings
Expand Down Expand Up @@ -145,14 +146,26 @@ def current_cohort(self):
"name": "Unassigned"
}

return {
"name": assignment.cohort.name,
"id": assignment.cohort.id,
"client_course": assignment.cohort.info.client_course_url,
"server_course": assignment.cohort.info.server_course_url,
"zoom_url": assignment.cohort.info.zoom_url,
"start": assignment.cohort.start_date,
"end": assignment.cohort.end_date,
"github_org": assignment.cohort.info.student_organization_url,
"courses": assignment.cohort.courses.order_by('index').values('course__name', 'course__id', 'active'),
}
try:
return {
"name": assignment.cohort.name,
"id": assignment.cohort.id,
"client_course": assignment.cohort.info.client_course_url,
"server_course": assignment.cohort.info.server_course_url,
"zoom_url": assignment.cohort.info.zoom_url,
"start": assignment.cohort.start_date,
"end": assignment.cohort.end_date,
"github_org": assignment.cohort.info.student_organization_url,
"courses": assignment.cohort.courses.order_by('index').values('course__name', 'course__id', 'active'),
}
except Exception as ex:
logger = logging.getLogger("LearningPlatform")
logger.exception(getattr(ex, 'message', repr(ex)))

return {
"name": assignment.cohort.name,
"id": assignment.cohort.id,
"start": assignment.cohort.start_date,
"end": assignment.cohort.end_date,
"courses": assignment.cohort.courses.order_by('index').values('course__name', 'course__id', 'active'),
}

0 comments on commit 4bd4fc2

Please sign in to comment.