From f3721da4bfa93731e41130a077ef5bb1f0e3ba53 Mon Sep 17 00:00:00 2001 From: juuso-j Date: Wed, 14 Feb 2024 09:34:49 +0200 Subject: [PATCH] Remove value field from Result model --- .../management/commands/import_questions.py | 17 +++++++++-------- profiles/tests/test_import_questions.py | 7 +++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/profiles/management/commands/import_questions.py b/profiles/management/commands/import_questions.py index 7b8100f..7d7aada 100644 --- a/profiles/management/commands/import_questions.py +++ b/profiles/management/commands/import_questions.py @@ -91,13 +91,13 @@ def get_and_create_results(data: pd.DataFrame) -> list: for i, column in enumerate(columns): col_data = data[column] topic = get_language_dict(data.columns[RESULT_COLUMNS[0] + i]) - value = get_language_dict(col_data[1]) description = get_language_dict(col_data[0]) - filter = {} + filter = {"topic": topic["fi"]} + update_filter = {} + for lang in LANGUAGES: - filter[f"topic_{lang}"] = topic[lang] - filter[f"value_{lang}"] = value[lang] - filter[f"description_{lang}"] = description[lang] + update_filter[f"topic_{lang}"] = topic[lang] + update_filter[f"description_{lang}"] = description[lang] queryset = Result.objects.filter(**filter) if queryset.count() == 0: result = Result.objects.create(**filter) @@ -109,6 +109,8 @@ def get_and_create_results(data: pd.DataFrame) -> list: if id in results_to_delete: results_to_delete.remove(id) + Result.objects.filter(**filter).update(**update_filter) + results.append(result) Result.objects.filter(id__in=results_to_delete).delete() logger.info(f"Created {num_created} Results") @@ -218,17 +220,16 @@ def save_questions(excel_data: pd.DataFrame, results: list): if queryset.count() == 0: question = Question.objects.create(**filter) - Question.objects.filter(**filter).update(**update_filter) logger.info(f"Created question: {questions['fi']}") num_created += 1 else: logger.info(f"Found question: {questions['fi']}") - Question.objects.filter(**filter).update(**update_filter) - question = queryset.first() id = queryset.first().id if id in questions_to_delete: questions_to_delete.remove(id) + + Question.objects.filter(**filter).update(**update_filter) if row_data[CONDITION_COLUMN]: create_conditions(row_data[CONDITION_COLUMN], question) sub_question_order_number = 0 diff --git a/profiles/tests/test_import_questions.py b/profiles/tests/test_import_questions.py index 7b7e43d..3b2f5e9 100644 --- a/profiles/tests/test_import_questions.py +++ b/profiles/tests/test_import_questions.py @@ -33,11 +33,10 @@ def test_import_questions(): assert results_qs.count() == 6 autoilija = Result.objects.get(topic_fi="Autoilija") assert results_qs[0].topic_fi == autoilija.topic_fi - assert results_qs[1].value_sv == "Rutinerad Räv" - assert results_qs[2].description_en[0:15] == "Travels by foot" + assert "You know where" in results_qs[1].description_en + assert "Fotgängare" in results_qs[2].topic_sv assert results_qs[3].topic_en == "Public transport passenger" - assert results_qs[4].value_fi == "Kokeileva Kauris" - assert results_qs[5].description_sv[-12:] == "använda bil." + assert "Maas" in results_qs[4].topic_fi # Test questions assert Question.objects.count() == 16