Skip to content

Commit

Permalink
Fix error with manual assessment "next" link
Browse files Browse the repository at this point in the history
Fixed error when previous submitter was not found.
  • Loading branch information
ihalaij1 authored and murhum1 committed Jul 19, 2024
1 parent 0bb1e92 commit fd469c1
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions exercise/staff_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,24 +377,25 @@ def get(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:
total_submitters = submitters.count()
previous_user_id = request.GET.get('prev')
if previous_user_id:
# get the previous time
previous_time = submitters.filter(user__id=previous_user_id).first().earliest_submission

# remove the submitters who have been assessed (we do this after we've found the
# previous submitter's time as the previous submitter might have been assessed)
submitters = submitters.filter(count_assessed=0)

# Find specifically the submitter who's submission was submitted right after this one
submitters = submitters.filter(earliest_submission__gt=previous_time)
submitter = submitters.first()
previous_submitter = submitters.filter(user__id=previous_user_id).first()
if previous_submitter:
# get the previous time
previous_time = previous_submitter.earliest_submission
if previous_time:
# remove the submitters who have been assessed (we do this after we've found the
# previous submitter's time as the previous submitter might have been assessed)
submitters = submitters.filter(count_assessed=0)

# Find specifically the submitter who's submission was submitted right after this one
submitters = submitters.filter(earliest_submission__gt=previous_time)
submitter = submitters.first()

if not submitter:
submitters = submitters.filter(count_assessed=0)
submitter = submitters.first()

# the number of submitters that we have after filtering
submitters_after = submitters.count()
filtered_submitters = total_submitters - submitters_after + 1
# Subtract the number of submitters that we have after filtering from the total_submitters
filtered_submitters = total_submitters - submitters.count() + 1

if not submitter:
# There are no more unassessed submitters.
Expand All @@ -406,7 +407,10 @@ def get(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:
ids = cache.submission_ids(exercise_id=self.exercise.id, best=True, fallback_to_last=True)
if not ids:
raise Http404()
percentage = f"{int(filtered_submitters / total_submitters * 100)}%"
if total_submitters == 0:
percentage = "0%"
else:
percentage = f"{int(filtered_submitters / total_submitters * 100)}%"
self.request.session['manually_assessed_counter'] = (
f"{filtered_submitters} / {total_submitters} ({percentage})"
)
Expand Down

0 comments on commit fd469c1

Please sign in to comment.