Skip to content

Commit

Permalink
only display a users assignments that match marker stage
Browse files Browse the repository at this point in the history
  • Loading branch information
struan committed Nov 2, 2023
1 parent c207cd7 commit 10c0796
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
2 changes: 2 additions & 0 deletions crowdsourcer/templates/crowdsourcer/assignments.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ <h1 class="mb-4">{% if show_users %}All{% else %}Your{% endif %} assignments</h1
<tr>
{% if show_users %}
<th>Assessor</th>
<th>Stage</th>
{% endif %}
<th>Section</th>
<th>Progress</th>
Expand All @@ -21,6 +22,7 @@ <h1 class="mb-4">{% if show_users %}All{% else %}Your{% endif %} assignments</h1
<tr>
{% if show_users %}
<td><a href="{% url "volunteer_progress" assignment.assignment.user.id %}">{{ assignment.assignment.user.username }}</a></td>
<td>{{ assignment.assignment.response_type }}</td>
{% endif %}
<td>
<a href="{% url section_link assignment.assignment.section.title %}">{{ assignment.assignment.section.title }}</a>
Expand Down
10 changes: 8 additions & 2 deletions crowdsourcer/tests/test_audit_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class TestAssignmentView(BaseTestCase):

def test_basics(self):
u = User.objects.get(username="marker")
rt = ResponseType.objects.get(type="Audit")
m, _ = Marker.objects.get_or_create(user=u)
m.response_type = rt
m.save()

self.client.force_login(u)
self.user = u

Expand Down Expand Up @@ -82,10 +87,11 @@ def test_non_audit_assigned_user(self):
first = assignments[0]

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

url = reverse(
"authority_question_edit", args=("Aberdeenshire Council", "Transport")
"authority_question_edit",
args=("Aberdeenshire Council", "Transport"),
)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
Expand Down
18 changes: 17 additions & 1 deletion crowdsourcer/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ def test_non_first_mark_assigned_user(self):
self.assertEqual(context["section_link"], "audit_section_authorities")
progress = context["progress"]

self.assertEqual(len(progress), 0)

# have to delete to prevent a duplicate assignment
Assigned.objects.filter(response_type=rt).delete()
Assigned.objects.filter(user=u).update(response_type=rt)
response = self.client.get("/")
self.assertEqual(response.status_code, 200)

context = response.context
progress = context["progress"]
self.assertEqual(len(progress), 2)

first = progress[0]
Expand Down Expand Up @@ -195,7 +205,7 @@ def test_no_access_unless_assigned(self):
response = self.client.get(url)
self.assertEqual(response.status_code, 403)

Assigned.objects.create(
a = Assigned.objects.create(
user=self.user,
section=Section.objects.get(title="Biodiversity"),
authority=PublicAuthority.objects.get(name="Aberdeenshire Council"),
Expand All @@ -204,6 +214,12 @@ def test_no_access_unless_assigned(self):
response = self.client.get(url)
self.assertEqual(response.status_code, 200)

a.active = False
a.save()

response = self.client.get(url)
self.assertEqual(response.status_code, 403)

def test_save(self):
url = reverse(
"authority_question_edit", args=("Aberdeenshire Council", "Transport")
Expand Down
27 changes: 16 additions & 11 deletions crowdsourcer/views/marking.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ def get_queryset(self):
active=True,
)
if user.is_superuser is False:
if hasattr(user, "marker"):
m = user.marker
qs = qs.filter(response_type=m.response_type)
else:
qs = qs.filter(response_type__type="First Mark")
qs = qs.filter(user=user)
else:
qs = qs.filter(user__is_active=True)
Expand Down Expand Up @@ -150,20 +155,20 @@ def get_context_data(self, **kwargs):
{"assignment": assignment, "complete": complete, "total": total}
)

context["progress"] = progress
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
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"
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
context["page_title"] = "Assignments"
context["section_link"] = section_link

return context

Expand Down

0 comments on commit 10c0796

Please sign in to comment.