Skip to content

Commit

Permalink
Remove value field from Result model
Browse files Browse the repository at this point in the history
  • Loading branch information
juuso-j committed Feb 14, 2024
1 parent 848580a commit f3721da
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
17 changes: 9 additions & 8 deletions profiles/management/commands/import_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions profiles/tests/test_import_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f3721da

Please sign in to comment.