Fix soil variant spreadsheet import bug where all variants added

This commit is contained in:
Dana Lambert 2021-10-20 12:36:06 +13:00
parent c4fdd04e8b
commit cb348b0f5d

View file

@ -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,9 +110,12 @@ 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]]
@ -120,7 +123,7 @@ def get_plant_json_from_row(row_data):
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']