Skip to content

Commit 95337e7

Browse files
committed
update code to handle authorities belonging to sessions
1 parent ca56691 commit 95337e7

File tree

8 files changed

+34
-15
lines changed

8 files changed

+34
-15
lines changed

crowdsourcer/fixtures/authorities.json

+8-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"website": "https://www.aberdeencity.gov.uk",
99
"country": "scotland",
1010
"type": "UTA",
11-
"questiongroup": 1
11+
"questiongroup": 1,
12+
"marking_session": [1,2]
1213
}
1314
},
1415
{
@@ -20,7 +21,8 @@
2021
"website": "https://www.aberdeenshire.gov.uk",
2122
"country": "scotland",
2223
"type": "UTA",
23-
"questiongroup": 1
24+
"questiongroup": 1,
25+
"marking_session": [1,2]
2426
}
2527
},
2628
{
@@ -32,7 +34,8 @@
3234
"website": "https://www.adur-worthing.gov.uk/",
3335
"country": "england",
3436
"type": "DIS",
35-
"questiongroup": 2
37+
"questiongroup": 2,
38+
"marking_session": [1,2]
3639
}
3740
},
3841
{
@@ -45,7 +48,8 @@
4548
"questiongroup": 2,
4649
"country": "northern ireland",
4750
"type": "NID",
48-
"do_not_mark": true
51+
"do_not_mark": true,
52+
"marking_session": [1]
4953
}
5054
}
5155
]

crowdsourcer/fixtures/authorities_ca.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"name": "A Combined Authority",
88
"website": "https://www.example.org",
99
"type": "COMB",
10-
"questiongroup": 5
10+
"questiongroup": 5,
11+
"marking_session": [1]
1112
}
1213
}
1314
]

crowdsourcer/management/commands/add_authority_to_session.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def handle(self, quiet: bool = False, *args, **options):
6262
count = 0
6363
for index, row in df.iterrows():
6464
try:
65-
authority = PublicAuthority.options.get(id=row["gssNumber"])
65+
authority = PublicAuthority.objects.get(unique_id=row["gssNumber"])
6666
count += 1
6767
except PublicAuthority.DoesNotExist:
6868
self.stderr.write(f"No authority found for {row['gssNumber']}")

crowdsourcer/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def response_counts(
176176
question_types = Question.VOLUNTEER_TYPES
177177

178178
authorities = cls.objects.filter(
179-
questiongroup__question__in=questions
179+
marking_session=marking_session, questiongroup__question__in=questions
180180
).annotate(
181181
num_questions=Subquery(
182182
Question.objects.filter(

crowdsourcer/scoring.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,9 @@ def get_blank_section_scores(session):
338338
}
339339

340340
for council in PublicAuthority.objects.filter(
341-
questiongroup__marking_session=session, do_not_mark=False
341+
marking_session=session,
342+
questiongroup__marking_session=session,
343+
do_not_mark=False,
342344
).all():
343345
if council.type == "COMB":
344346
weighted[council.name] = ca_sections.copy()
@@ -564,7 +566,7 @@ def get_scoring_object(session):
564566
scoring["council_control"] = control
565567
scoring["councils"] = {}
566568
for council in PublicAuthority.objects.filter(
567-
questiongroup__marking_session=session
569+
marking_session=session, questiongroup__marking_session=session
568570
):
569571
scoring["councils"][council.name] = council
570572

crowdsourcer/views/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ def test_func(self):
379379
def get_queryset(self):
380380
rt = ResponseType.objects.get(type=self.stage)
381381
qs = PublicAuthority.objects.filter(
382-
questiongroup__marking_session=self.request.current_session
382+
marking_session=self.request.current_session,
383+
questiongroup__marking_session=self.request.current_session,
383384
).annotate(
384385
num_sections=Subquery(
385386
Assigned.objects.filter(

crowdsourcer/views/progress.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ def get_queryset(self):
6666
response_type = ResponseType.objects.get(type=self.stage)
6767
qs = (
6868
PublicAuthority.objects.filter(
69-
questiongroup__marking_session=self.request.current_session
69+
marking_session=self.request.current_session,
70+
questiongroup__marking_session=self.request.current_session,
7071
)
7172
.annotate(
7273
num_questions=Subquery(
@@ -399,7 +400,8 @@ def test_func(self):
399400
def get_queryset(self):
400401
authorities = (
401402
PublicAuthority.objects.filter(
402-
questiongroup__marking_session=self.request.current_session
403+
marking_session=self.request.current_session,
404+
questiongroup__marking_session=self.request.current_session,
403405
)
404406
.annotate(
405407
has_logged_in=Subquery(

crowdsourcer/views/volunteers.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@
1414
VolunteerAssignmentFormset,
1515
VolunteerBulkAssignForm,
1616
)
17-
from crowdsourcer.models import Assigned, Marker, PublicAuthority, ResponseType, Section
17+
from crowdsourcer.models import (
18+
Assigned,
19+
Marker,
20+
MarkingSession,
21+
PublicAuthority,
22+
ResponseType,
23+
Section,
24+
)
1825

1926
logger = logging.getLogger(__name__)
2027

@@ -154,8 +161,10 @@ def get_queryset(self):
154161
):
155162
return []
156163

164+
marking_session = MarkingSession.objects.get(id=self.request.GET["ms"])
157165
return PublicAuthority.objects.filter(
158-
questiongroup__marking_session__id=self.request.GET["ms"]
166+
marking_session=marking_session,
167+
questiongroup__marking_session=marking_session,
159168
).exclude(
160169
id__in=Assigned.objects.filter(
161170
response_type=self.request.GET["rt"],
@@ -236,7 +245,7 @@ def form_valid(self, form):
236245
).values("authority")
237246

238247
to_assign = PublicAuthority.objects.filter(
239-
questiongroup__marking_session=ms
248+
marking_session=ms, questiongroup__marking_session=ms
240249
).exclude(id__in=assigned)[:num_assignments]
241250

242251
for a in to_assign:

0 commit comments

Comments
 (0)