Skip to content
Open
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
10 changes: 8 additions & 2 deletions evap/staff/templates/staff_semester_flagged_textanswers.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ <h5 class="{% if not forloop.first %}mt-3{% endif %} mb-2">
{{ evaluation_flagged_textanswers.grouper }}
</a>
</h5>
{% regroup evaluation_flagged_textanswers.list by assignment.question.text as flagged_textanswers_by_question %}
<ul>
{% for textanswer in evaluation_flagged_textanswers.list %}
<li>{{ textanswer.answer }}</li>
{% for question_flagged_textanswers in flagged_textanswers_by_question %}
<h6 class="{% if not forloop.first %}mt-3{% endif %} mb-2">{{ question_flagged_textanswers.grouper }}</h6>
<ul>
{% for textanswer in question_flagged_textanswers.list %}
<li>{{ textanswer.answer }}</li>
{% endfor %}
</ul>
{% endfor %}
</ul>
{% endfor %}
Expand Down
50 changes: 32 additions & 18 deletions evap/staff/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3141,51 +3141,65 @@ def test_textanswers_showing_up(self):


class TestSemesterFlaggedTextAnswersView(WebTestStaffMode):
def test_correct_answers_show_up(self):
semester = baker.make(Semester)
@classmethod
def setUpTestData(cls):
cls.semester = baker.make(Semester)

url = reverse("staff:semester_flagged_textanswers", args=[semester.pk])
cls.url = reverse("staff:semester_flagged_textanswers", args=[cls.semester.pk])

manager = make_manager()
student = baker.make(UserProfile)
evaluations = baker.make(
Evaluation, course__semester=semester, participants=[student], _quantity=3, _bulk_create=True
cls.manager = make_manager()
cls.student = baker.make(UserProfile)
cls.evaluations = baker.make(
Evaluation, course__semester=cls.semester, participants=[cls.student], _quantity=3, _bulk_create=True
)
textanswers = [
cls.textanswers = [
[baker.make(TextAnswer, answer=f"Answer {i} {j}", contribution__evaluation=evaluation) for j in range(3)]
for i, evaluation in enumerate(evaluations)
for i, evaluation in enumerate(cls.evaluations)
]

response = self.app.get(url, user=manager)
cls.flagged_ids = [(0, 0), (0, 1), (1, 0)]

def test_correct_answers_show_up(self):
response = self.app.get(self.url, user=self.manager)
self.assertContains(response, "There are no flagged textanswers")

flagged_ids = [(0, 0), (0, 1), (1, 0)]
expected_texts = [
"Answer 0 0",
"Answer 0 1",
"Answer 1 0",
evaluations[0].full_name,
evaluations[1].full_name,
self.evaluations[0].full_name,
self.evaluations[1].full_name,
]
unexpected_texts = [
"There are no flagged textanswers",
"Answer 0 2",
"Answer 1 1",
"Answer 2 0",
evaluations[2].full_name,
self.evaluations[2].full_name,
]

for i, j in flagged_ids:
textanswers[i][j].is_flagged = True
textanswers[i][j].save()
for i, j in self.flagged_ids:
self.textanswers[i][j].is_flagged = True
self.textanswers[i][j].save()

response = self.app.get(url, user=manager)
response = self.app.get(self.url, user=self.manager)

for text in expected_texts:
self.assertContains(response, text)
for text in unexpected_texts:
self.assertNotContains(response, text)

def test_answer_grouping_and_question_order(self):
for i, j in self.flagged_ids:
self.textanswers[i][j].is_flagged = True
self.textanswers[i][j].save()
Comment on lines +3193 to +3195

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.

both tests now do this, I think it would make more sense to move this into the shared setup code (where we also define flagged_ids)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

test_correct_answers_show_up checks first if there aren't any flagged textanswers, thats why I kept it duplicated


response = self.app.get(self.url, user=self.manager).body.decode()
for row in self.textanswers:
for textanswer in row:
Comment on lines +3198 to +3199

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.

I may just be too tired, but is there any value in having the textanswers be stored in two levels of nested lists here, or could we flatten that to just a one-dimensional list?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I also thought about that, but was too tired to think about it. I'll see if something breaks, when I change it.

if textanswer.is_flagged:
self.assertLess(response.index(textanswer.question.text), response.index(textanswer.answer))


class TestQuestionnaireNewVersionView(WebTestStaffMode):
@classmethod
Expand Down
2 changes: 1 addition & 1 deletion evap/staff/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,7 @@ def semester_flagged_textanswers(request: HttpRequest, semester_id: int) -> Http
flagged_textanswers = TextAnswer.objects.filter(
is_flagged=True,
contribution__evaluation__course__semester=semester,
).order_by("contribution__evaluation")
).order_by("contribution__evaluation", "assignment__questionnaire", "assignment__question")
Comment thread
just-spafi marked this conversation as resolved.

template_data = {
"semester": semester,
Expand Down