Skip to content

Commit

Permalink
make sure progress stats and links reflect assigned stage
Browse files Browse the repository at this point in the history
  • Loading branch information
struan committed Nov 2, 2023
1 parent 10c0796 commit ec13762
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
2 changes: 1 addition & 1 deletion crowdsourcer/templates/crowdsourcer/assignments.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h1 class="mb-4">{% if show_users %}All{% else %}Your{% endif %} assignments</h1
<td>{{ assignment.assignment.response_type }}</td>
{% endif %}
<td>
<a href="{% url section_link assignment.assignment.section.title %}">{{ assignment.assignment.section.title }}</a>
<a href="{% url assignment.section_link assignment.assignment.section.title %}">{{ assignment.assignment.section.title }}</a>
</td>
<td>
<div class="progress progress-thin mb-2">
Expand Down
6 changes: 4 additions & 2 deletions crowdsourcer/tests/test_audit_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_non_audit_assigned_user(self):
self.assertEqual(len(assignments), 2)
first = assignments[0]

self.assertEqual(context["section_link"], "section_authorities")
self.assertEqual(first["section_link"], "section_authorities")
self.assertEqual(first["assignment"].section.title, "Buildings & Heating")

url = reverse(
Expand All @@ -107,7 +107,9 @@ def test_non_audit_assigned_user(self):
self.assertEqual(response.status_code, 200)

context = response.context
self.assertEqual(context["section_link"], "audit_section_authorities")
assignments = context["progress"]
first = assignments[0]
self.assertEqual(first["section_link"], "audit_section_authorities")

rt = ResponseType.objects.get(type="Right of Reply")
m.response_type = rt
Expand Down
3 changes: 2 additions & 1 deletion crowdsourcer/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def test_non_first_mark_assigned_user(self):
context = response.context
self.assertFalse(context["show_users"])

self.assertEqual(context["section_link"], "audit_section_authorities")
progress = context["progress"]

self.assertEqual(len(progress), 0)
Expand All @@ -101,7 +100,9 @@ def test_non_first_mark_assigned_user(self):
first = progress[0]
second = progress[1]
self.assertEqual(first["assignment"].section.title, "Buildings & Heating")
self.assertEqual(first["section_link"], "audit_section_authorities")
self.assertEqual(second["assignment"].section.title, "Transport")
self.assertEqual(second["section_link"], "audit_section_authorities")


class TestAssignmentCompletionStats(BaseTestCase):
Expand Down
37 changes: 23 additions & 14 deletions crowdsourcer/views/marking.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,24 @@ def get_context_data(self, **kwargs):
assignments = (
context["assignments"]
.distinct("user_id", "section_id")
.select_related("section")
.select_related("section", "response_type")
)

types = Question.VOLUNTEER_TYPES
if self.current_stage.type == "Audit":
types = ["volunteer", "national_volunteer", "foi"]

first_mark = ResponseType.objects.get(type="First Mark")

progress = []
question_cache = {}
for assignment in assignments:
assignment_user = assignment.user
if hasattr(assignment_user, "marker"):
stage = assignment_user.marker.response_type
else:
stage = first_mark

if question_cache.get(assignment.section_id, None) is not None:
question_list = question_cache[assignment.section_id]
else:
Expand All @@ -134,9 +142,10 @@ def get_context_data(self, **kwargs):
]
if assignment.authority_id is not None:
authorities = Assigned.objects.filter(
active=True,
user=assignment.user_id,
section=assignment.section_id,
response_type=self.current_stage,
response_type=stage,
).values_list("authority_id", flat=True)
args.append(authorities)

Expand All @@ -151,24 +160,24 @@ def get_context_data(self, **kwargs):
total += 1
if count.num_responses == count.num_questions:
complete += 1

if assignment.response_type.type == "First Mark":
section_link = "section_authorities"
elif assignment.response_type.type == "Audit":
section_link = "audit_section_authorities"

progress.append(
{"assignment": assignment, "complete": complete, "total": total}
{
"assignment": assignment,
"complete": complete,
"total": total,
"section_link": section_link,
}
)

context["progress"] = progress

user_stage = self.current_stage.type
if hasattr(user, "marker"):
if user.marker.response_type:
user_stage = user.marker.response_type.type

if user_stage == "First Mark":
section_link = "section_authorities"
elif user_stage == "Audit":
section_link = "audit_section_authorities"

context["page_title"] = "Assignments"
context["section_link"] = section_link

return context

Expand Down

0 comments on commit ec13762

Please sign in to comment.