diff --git a/exercise/staff_views.py b/exercise/staff_views.py index d4be92b4f..b84940f24 100644 --- a/exercise/staff_views.py +++ b/exercise/staff_views.py @@ -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. @@ -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})" )