Skip to content

Commit

Permalink
allow matching option using score only in national data import
Browse files Browse the repository at this point in the history
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
  • Loading branch information
struan committed Dec 11, 2024
1 parent 13c1609 commit a6fea43
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions crowdsourcer/management/commands/import_national_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,13 @@ def get_score(self, q, row, details, authority):
score = 0
desc = "No"
else:
for opt in details["options"]:
if opt["score"] == score:
desc = opt["desc"]
break
if details.get("options"):
for opt in details["options"]:
if opt["score"] == score:
desc = opt["desc"]
break
else:
desc = None

return desc, score

Expand Down Expand Up @@ -271,7 +274,12 @@ def import_answers(self, user, rt, df, q, details):
option = None
if not details.get("update_points_only", False):
try:
option = Option.objects.get(question=q, description=score_desc)
if score_desc is not None:
option = Option.objects.get(
question=q, description=score_desc
)
else:
option = Option.objects.get(question=q, score=score)
except Option.DoesNotExist:
self.print_info(
f"No option found for {q.number}, {score_desc}, {authority.name}",
Expand Down

0 comments on commit a6fea43

Please sign in to comment.