Skip to content
Merged
Show file tree
Hide file tree
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
28 changes: 26 additions & 2 deletions evap/contributor/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from evap.evaluation.models import Contribution, Course, Evaluation, Questionnaire, UserProfile
from evap.evaluation.tests.tools import (
FuzzyInt,
WebTest,
WebTestWith200Check,
create_evaluation_with_responsible_and_editor,
Expand Down Expand Up @@ -82,8 +83,31 @@ class TestContributorView(WebTestWith200Check):

@classmethod
def setUpTestData(cls):
users = create_evaluation_with_responsible_and_editor()
cls.test_users = [users["editor"], users["responsible"]]
result = create_evaluation_with_responsible_and_editor()
cls.responsible = result["responsible"]
cls.test_users = [result["editor"], cls.responsible]

def test_num_queries_is_not_constant(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

haha :D

"""Current defect, see https://github.com/e-valuation/EvaP/issues/1229#issuecomment-4239035495."""
represented = baker.make(UserProfile, email="represented@example.com")
self.responsible.represented_users.add(represented)
evaluations = baker.make(
Evaluation,
name_en=iter(range(10)),
name_de=iter(range(10)),
state=Evaluation.State.PUBLISHED,
course__responsibles=[represented],
_quantity=10,
_bulk_create=True,
)
baker.make(
Contribution,
evaluation=iter(evaluations),
_quantity=10,
_bulk_create=True,
)
with self.assertNumQueries(FuzzyInt(80, 100)):
self.app.get(self.url, user=self.responsible)


class TestContributorEvaluationView(WebTestWith200Check):
Expand Down
14 changes: 10 additions & 4 deletions evap/contributor/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ def index(request):
)

own_evaluations = (
Evaluation.objects.filter(course__in=own_courses)
Evaluation.annotate_with_participant_and_voter_counts(Evaluation.objects.filter(course__in=own_courses))
.annotate(contributes_to=Exists(Evaluation.objects.filter(id=OuterRef("id"), contributions__contributor=user)))
.prefetch_related("course", "course__evaluations", "course__programs", "course__type", "course__semester")
.select_related("course", "course__type", "course__semester")
.prefetch_related("course__evaluations", "course__programs")
)
own_evaluations = [evaluation for evaluation in own_evaluations if evaluation.can_be_seen_by(user)]

Expand All @@ -77,9 +78,14 @@ def index(request):
)
)
)
delegated_evaluations = Evaluation.objects.filter(course__in=delegated_courses).prefetch_related(
"course", "course__evaluations", "course__programs", "course__type", "course__semester"
delegated_evaluations = (
Evaluation.annotate_with_participant_and_voter_counts(
Evaluation.objects.filter(course__in=delegated_courses)
)
.select_related("course", "course__type", "course__semester")
.prefetch_related("course__evaluations", "course__programs", "course__responsibles")
)

delegated_evaluations = [evaluation for evaluation in delegated_evaluations if evaluation.can_be_seen_by(user)]
for evaluation in delegated_evaluations:
evaluation.delegated_evaluation = True
Expand Down