From cb348b0f5ddba5033bbbfceb924fdfa6d0702ef2 Mon Sep 17 00:00:00 2001 From: Dana Lambert Date: Wed, 20 Oct 2021 12:36:06 +1300 Subject: [PATCH] Fix soil variant spreadsheet import bug where all variants added --- .../management/commands/createplantfixtures.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/backend/right_tree/api/management/commands/createplantfixtures.py b/backend/right_tree/api/management/commands/createplantfixtures.py index cba37a4..23c2c7d 100644 --- a/backend/right_tree/api/management/commands/createplantfixtures.py +++ b/backend/right_tree/api/management/commands/createplantfixtures.py @@ -66,7 +66,7 @@ PLANT_JSON_TEMPLATE = { } -def check_field_type(field, field_value): +def check_field_value(field, field_value): """ Checks the validity of a feild value collected from the spreadsheet """ expected_field_type = PLANT_COLS[field]['expected_type'] @@ -110,17 +110,20 @@ def get_plant_json_from_row(row_data): plant_json_fields[model_field_name] = soil_orders_list elif field in {'wet', 'mesic', 'dry'}: - soil_variant_pk = SOIL_VARIANT_PK_MAPPING[field.capitalize()] - plant_json_fields[model_field_name] = plant_json_fields.get( - model_field_name, []) + [soil_variant_pk] + if row_data[field_index] != None: + soil_variant_pk = SOIL_VARIANT_PK_MAPPING[field.capitalize()] + plant_json_fields[model_field_name] = plant_json_fields.get( + model_field_name, []) + [soil_variant_pk] + else: + continue elif field in {'water', 'drought', 'frost', 'salinity'}: plant_json_fields[model_field_name] = TOLERANCE_PK_MAPPING[row_data[field_index]] elif field in PLANT_COLS: plant_json_fields[model_field_name] = row_data[field_index] - - check_field_type(field, plant_json_fields[model_field_name]) + + check_field_value(field, plant_json_fields[model_field_name]) except Exception as e: name_index = INFO_COL_INDEXES['name']