Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import jsonschema
import pandas as pd
from sqlalchemy.exc import SQLAlchemyError
from constance import config
from django.conf import settings
from django.contrib import auth
Expand Down Expand Up @@ -460,11 +461,18 @@ def grade_distribution(request, course_id=0):
(select current_grade from user where sis_name=%(current_user)s and course_id=%(course_id)s) as current_user_grade
from user where course_id=%(course_id)s and enrollment_type=%(enrollment_type)s
"""
df = pd.read_sql(grade_score_sql, app_engine, params={
'current_user': current_user,
'course_id': course_id,
'enrollment_type': 'StudentEnrollment'
})
try:
logger.info(f"course_id={course_id}, current_user={current_user}")
df = pd.read_sql(grade_score_sql, app_engine, params={
'current_user': current_user,
'course_id': course_id,
'enrollment_type': 'StudentEnrollment'
})
except SQLAlchemyError as e:
grade_distribution_sql_error_msg = f'Error running grade distribution sql with course_id={course_id}, current_user={current_user} enrollment_type=StudentEnrollment'
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comma between '{current_user}' and 'enrollment_type'. Should be 'current_user={current_user}, enrollment_type=StudentEnrollment'.

Suggested change
grade_distribution_sql_error_msg = f'Error running grade distribution sql with course_id={course_id}, current_user={current_user} enrollment_type=StudentEnrollment'
grade_distribution_sql_error_msg = f'Error running grade distribution sql with course_id={course_id}, current_user={current_user}, enrollment_type=StudentEnrollment'

Copilot uses AI. Check for mistakes.
logger.error(f"{grade_distribution_sql_error_msg} sql={grade_score_sql} error={e}")
return HttpResponse(json.dumps({'gd_disable':'true','gd_msg': grade_distribution_sql_error_msg}), content_type='application/json')
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use JsonResponse instead of manually constructing JSON with HttpResponse and json.dumps. This provides better consistency with Django conventions and automatically sets the content type.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The boolean value 'true' is returned as a string. Consider using a boolean type (True) in the dictionary for consistency, as json.dumps will correctly serialize it to the JSON boolean 'true'.

Copilot uses AI. Check for mistakes.

if len(df) <= config.GRADE_DISTRIBUTION_MINIMUM:
grade_distribution_limit_msg = f'Grade Distribution view is disabled because the course enrollment is less than {config.GRADE_DISTRIBUTION_MINIMUM}'
logger.error(f"Course enrollment count {len(df)} Hence the {grade_distribution_limit_msg}")
Expand Down