Skip to content

Commit

Permalink
update code to handle authorities belonging to sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
struan committed Jun 20, 2024
1 parent 581b8d8 commit 559013f
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 14 deletions.
12 changes: 8 additions & 4 deletions crowdsourcer/fixtures/authorities.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"website": "https://www.aberdeencity.gov.uk",
"country": "scotland",
"type": "UTA",
"questiongroup": 1
"questiongroup": 1,
"marking_session": [1,2]
}
},
{
Expand All @@ -20,7 +21,8 @@
"website": "https://www.aberdeenshire.gov.uk",
"country": "scotland",
"type": "UTA",
"questiongroup": 1
"questiongroup": 1,
"marking_session": [1,2]
}
},
{
Expand All @@ -32,7 +34,8 @@
"website": "https://www.adur-worthing.gov.uk/",
"country": "england",
"type": "DIS",
"questiongroup": 2
"questiongroup": 2,
"marking_session": [1,2]
}
},
{
Expand All @@ -45,7 +48,8 @@
"questiongroup": 2,
"country": "northern ireland",
"type": "NID",
"do_not_mark": true
"do_not_mark": true,
"marking_session": [1]
}
}
]
3 changes: 2 additions & 1 deletion crowdsourcer/fixtures/authorities_ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"name": "A Combined Authority",
"website": "https://www.example.org",
"type": "COMB",
"questiongroup": 5
"questiongroup": 5,
"marking_session": [1]
}
}
]
2 changes: 1 addition & 1 deletion crowdsourcer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def response_counts(
question_types = Question.VOLUNTEER_TYPES

authorities = cls.objects.filter(
questiongroup__question__in=questions
marking_session=marking_session, questiongroup__question__in=questions
).annotate(
num_questions=Subquery(
Question.objects.filter(
Expand Down
6 changes: 4 additions & 2 deletions crowdsourcer/scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ def get_blank_section_scores(session):
}

for council in PublicAuthority.objects.filter(
questiongroup__marking_session=session, do_not_mark=False
marking_session=session,
questiongroup__marking_session=session,
do_not_mark=False,
).all():
if council.type == "COMB":
weighted[council.name] = ca_sections.copy()
Expand Down Expand Up @@ -564,7 +566,7 @@ def get_scoring_object(session):
scoring["council_control"] = control
scoring["councils"] = {}
for council in PublicAuthority.objects.filter(
questiongroup__marking_session=session
marking_session=session, questiongroup__marking_session=session
):
scoring["councils"][council.name] = council

Expand Down
3 changes: 2 additions & 1 deletion crowdsourcer/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ def test_func(self):
def get_queryset(self):
rt = ResponseType.objects.get(type=self.stage)
qs = PublicAuthority.objects.filter(
questiongroup__marking_session=self.request.current_session
marking_session=self.request.current_session,
questiongroup__marking_session=self.request.current_session,
).annotate(
num_sections=Subquery(
Assigned.objects.filter(
Expand Down
6 changes: 4 additions & 2 deletions crowdsourcer/views/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def get_queryset(self):
response_type = ResponseType.objects.get(type=self.stage)
qs = (
PublicAuthority.objects.filter(
questiongroup__marking_session=self.request.current_session
marking_session=self.request.current_session,
questiongroup__marking_session=self.request.current_session,
)
.annotate(
num_questions=Subquery(
Expand Down Expand Up @@ -399,7 +400,8 @@ def test_func(self):
def get_queryset(self):
authorities = (
PublicAuthority.objects.filter(
questiongroup__marking_session=self.request.current_session
marking_session=self.request.current_session,
questiongroup__marking_session=self.request.current_session,
)
.annotate(
has_logged_in=Subquery(
Expand Down
15 changes: 12 additions & 3 deletions crowdsourcer/views/volunteers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@
VolunteerAssignmentFormset,
VolunteerBulkAssignForm,
)
from crowdsourcer.models import Assigned, Marker, PublicAuthority, ResponseType, Section
from crowdsourcer.models import (
Assigned,
Marker,
MarkingSession,
PublicAuthority,
ResponseType,
Section,
)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -154,8 +161,10 @@ def get_queryset(self):
):
return []

marking_session = MarkingSession.objects.get(id=self.request.GET["ms"])
return PublicAuthority.objects.filter(
questiongroup__marking_session__id=self.request.GET["ms"]
marking_session=marking_session,
questiongroup__marking_session=marking_session,
).exclude(
id__in=Assigned.objects.filter(
response_type=self.request.GET["rt"],
Expand Down Expand Up @@ -236,7 +245,7 @@ def form_valid(self, form):
).values("authority")

to_assign = PublicAuthority.objects.filter(
questiongroup__marking_session=ms
marking_session=ms, questiongroup__marking_session=ms
).exclude(id__in=assigned)[:num_assignments]

for a in to_assign:
Expand Down

0 comments on commit 559013f

Please sign in to comment.