Skip to content

Commit

Permalink
Resource.grade_user also returns completion_status
Browse files Browse the repository at this point in the history
Working towards #323, the method Resource.grade_user also returns a
completion_status. If the resource is no longer available, then the
completion status is always "completed".
  • Loading branch information
christianp committed Jul 12, 2024
1 parent 85b91b2 commit 64f41ca
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
9 changes: 8 additions & 1 deletion numbas_lti/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,17 +493,24 @@ def grade_user(self,user):
Find the attempt representing the user's grade at this resource.
Depends on ``grading_method``.
"""

methods = {
'highest': '-scaled_score',
'last': '-start_time',
}


attempts = self.attempts.filter(user=user)
if not self.include_incomplete_attempts:
attempts = attempts.filter(completion_status='completed')
if not attempts.exists():
return None

attempt = attempts.order_by(methods[self.grading_method]).first()
return attempt

completion_status = attempt.completion_status if self.is_available(user) else 'completed'

return attempt, completion_status

def students(self):
return User.objects.filter(attempts__resource=self, attempts__deleted=False).distinct().order_by('last_name','first_name')
Expand Down
10 changes: 5 additions & 5 deletions numbas_lti/report_outcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def report_outcome_lti_13(resource, user_data):

user = user_data.user

attempt = resource.grade_user(user)
attempt, completion_status = resource.grade_user(user)

if attempt.end_time is not None:
time = attempt.end_time
Expand All @@ -84,11 +84,11 @@ def report_outcome_lti_13(resource, user_data):
'not attempted': 'Initialized',
'incomplete': 'InProgress',
'completed': 'Completed',
}[attempt.completion_status]
}[completion_status]

if attempt.completion_status == 'completed':
if completion_status == 'completed':
grading_progress = 'FullyGraded'
elif attempt.completion_status == 'incomplete':
elif completion_status == 'incomplete':
grading_progress = 'Pending'
else:
grading_progress = 'NotReady'
Expand Down Expand Up @@ -147,7 +147,7 @@ def report_outcome_lti_11(resource,user_data):
if user.is_anonymous:
raise ReportOutcomeException(None,'User is anonymous')
message_identifier = uuid.uuid4().int & (1<<64)-1
attempt = resource.grade_user(user)
attempt, completion_status = resource.grade_user(user)
result = attempt.scaled_score

if user_data.lti_11.lis_result_sourcedid:
Expand Down
2 changes: 1 addition & 1 deletion numbas_lti/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def resource_scores_csv_report(fr):
for student in resource.students().all():
user_data = resource.user_data(student)
username = '' if user_data is None else user_data.get_source_id()
attempt = resource.grade_user(student)
attempt, completion_status = resource.grade_user(student)
scaled_score = attempt.scaled_score
student_attempts = resource.attempts.filter(user=student)
max_score = max(a.max_score for a in student_attempts) if student_attempts.exists() else 0
Expand Down
2 changes: 1 addition & 1 deletion numbas_lti/views/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def summarise_extra_student(student):
}

def summarise_student(student):
attempt = resource.grade_user(student)
attempt, completion_status = resource.grade_user(student)
score = attempt.scaled_score if attempt else 0
lti_data = student.lti_data.filter(resource=resource).last()

Expand Down

0 comments on commit 64f41ca

Please sign in to comment.