Skip to content
Snippets Groups Projects
Unverified Commit 673bb09d authored by Johannes Wolf's avatar Johannes Wolf Committed by GitHub
Browse files

Order due evaluations by time and name (#1674)


* fix #1612; sort due evaluations by due date, then by name

Co-authored-by: default avatarRichard Ebeling <He3lixxx@users.noreply.github.com>
parent f8119b44
Branches
No related tags found
No related merge requests found
import logging import logging
import operator
import secrets import secrets
import uuid import uuid
from collections import defaultdict, namedtuple from collections import defaultdict, namedtuple
...@@ -1711,15 +1710,13 @@ class UserProfile(AbstractBaseUser, PermissionsMixin): ...@@ -1711,15 +1710,13 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
return self.evaluations_voted_for.order_by("course__semester__created_at", "name_de") return self.evaluations_voted_for.order_by("course__semester__created_at", "name_de")
def get_sorted_due_evaluations(self): def get_sorted_due_evaluations(self):
due_evaluations = dict() evaluations_and_days_left = (
for evaluation in Evaluation.objects.filter(participants=self, state=Evaluation.State.IN_EVALUATION).exclude( (evaluation, evaluation.days_left_for_evaluation)
voters=self for evaluation in Evaluation.objects.filter(
): participants=self, state=Evaluation.State.IN_EVALUATION
due_evaluations[evaluation] = (evaluation.vote_end_date - date.today()).days ).exclude(voters=self)
)
# Sort evaluations by number of days left for evaluation and bring them to following format: return sorted(evaluations_and_days_left, key=lambda tup: (tup[1], tup[0].full_name))
# [(evaluation, due_in_days), ...]
return sorted(due_evaluations.items(), key=operator.itemgetter(1))
def validate_template(value): def validate_template(value):
......
...@@ -627,6 +627,39 @@ class TestUserProfile(TestCase): ...@@ -627,6 +627,39 @@ class TestUserProfile(TestCase):
user = baker.make(UserProfile, email="test@example.com") user = baker.make(UserProfile, email="test@example.com")
self.assertEqual(user.email, "test@institution.com") self.assertEqual(user.email, "test@institution.com")
def test_get_sorted_due_evaluations(self):
student = baker.make(UserProfile, email="student@example.com")
course = baker.make(Course)
evaluation1 = baker.make(
Evaluation,
course=course,
name_en="C",
name_de="C",
vote_end_date=date.today(),
state=Evaluation.State.IN_EVALUATION,
participants=[student],
)
evaluation2 = baker.make(
Evaluation,
course=course,
name_en="B",
name_de="B",
vote_end_date=date.today(),
state=Evaluation.State.IN_EVALUATION,
participants=[student],
)
evaluation3 = baker.make(
Evaluation,
course=course,
name_en="A",
name_de="A",
vote_end_date=date.today() + timedelta(days=1),
state=Evaluation.State.IN_EVALUATION,
participants=[student],
)
sorted_evaluations = student.get_sorted_due_evaluations()
self.assertEqual(sorted_evaluations, [(evaluation2, 0), (evaluation1, 0), (evaluation3, 1)])
class ParticipationArchivingTests(TestCase): class ParticipationArchivingTests(TestCase):
@classmethod @classmethod
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment