Skip to content

Commit 5d8b591

Browse files
committed
allow matching option using score only in national data import
as we're not creating the options from script it makes more sense to match using the score than the description as then don't need to do a lot of redundant config
1 parent 32c0a18 commit 5d8b591

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

crowdsourcer/management/commands/import_national_data.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,13 @@ def get_score(self, q, row, details, authority):
175175
score = 0
176176
desc = "No"
177177
else:
178-
for opt in details["options"]:
179-
if opt["score"] == score:
180-
desc = opt["desc"]
181-
break
178+
if details.get("options"):
179+
for opt in details["options"]:
180+
if opt["score"] == score:
181+
desc = opt["desc"]
182+
break
183+
else:
184+
desc = None
182185

183186
return desc, score
184187

@@ -271,7 +274,12 @@ def import_answers(self, user, rt, df, q, details):
271274
option = None
272275
if not details.get("update_points_only", False):
273276
try:
274-
option = Option.objects.get(question=q, description=score_desc)
277+
if score_desc is not None:
278+
option = Option.objects.get(
279+
question=q, description=score_desc
280+
)
281+
else:
282+
option = Option.objects.get(question=q, score=score)
275283
except Option.DoesNotExist:
276284
self.print_info(
277285
f"No option found for {q.number}, {score_desc}, {authority.name}",

0 commit comments

Comments
 (0)