From a6fea438268f8ac93d4ddb78d9b5ccddadeebabc Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 11 Dec 2024 11:50:01 +0000 Subject: [PATCH] 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 --- .../commands/import_national_data.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/crowdsourcer/management/commands/import_national_data.py b/crowdsourcer/management/commands/import_national_data.py index 7888800..d9aab2f 100644 --- a/crowdsourcer/management/commands/import_national_data.py +++ b/crowdsourcer/management/commands/import_national_data.py @@ -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 @@ -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}",