From 443f1deb88e2ea368742d84a5f2d54f62b8c6df3 Mon Sep 17 00:00:00 2001 From: julianforeman Date: Wed, 6 Nov 2024 10:29:15 -0800 Subject: [PATCH] Making delimiter for splitting values in a function a kwarg argument --- django/api/constants/constants.py | 6 +++--- django/api/services/spreadsheet_uploader_prep.py | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/django/api/constants/constants.py b/django/api/constants/constants.py index 9a96ced7..cb6c5ea9 100644 --- a/django/api/constants/constants.py +++ b/django/api/constants/constants.py @@ -764,7 +764,7 @@ class CVPDataColumnMapping(Enum): "sheet_name": "ARC Data", "preparation_functions": [prepare_arc_project_tracking], "validation_functions": [ - {'function': validate_field_values, "columns": [], "kwargs": {"indices_offset":2, "fields_and_values": ARC_VALID_FIELD_VALUES}}, + {'function': validate_field_values, "columns": [], "kwargs": {"indices_offset":2, "fields_and_values": ARC_VALID_FIELD_VALUES, "delimiter": ","}}, {"function": region_checker, "columns": ['Economic Region'], "kwargs": {"indices_offset":2}}, ] }, @@ -828,7 +828,7 @@ class CVPDataColumnMapping(Enum): {"function": typo_checker, "columns": ["Applicant Name"], "kwargs": {"cutoff": 0.8, "indices_offset": 2}}, {"function": location_checker, "columns": ["City"], "kwargs": {"columns_to_features_map": {"City": LOCALITY_FEATURES_MAP}, "indices_offset":2}}, {"function": email_validator, "columns": ["Email"], "kwargs": {"indices_offset":2, "get_resolver": get_google_resolver}}, - {"function": validate_field_values, "columns": [], "kwargs": {"indices_offset":2, "fields_and_values": GER_VALID_FIELD_VALUES}}, + {"function": validate_field_values, "columns": [], "kwargs": {"indices_offset":2, "fields_and_values": GER_VALID_FIELD_VALUES, "delimiter": ","}}, ] }, "CVP Data": { @@ -837,7 +837,7 @@ class CVPDataColumnMapping(Enum): "column_mapping": CVPDataColumnMapping, "sheet_name": "Data", "preparation_functions": [prepare_cvp_data], - "validation_functions": [{"function": validate_field_values, "columns": [], "kwargs": {"indices_offset":2, "fields_and_values": CVP_DATA_VALID_FIELD_VALUES}},] + "validation_functions": [{"function": validate_field_values, "columns": [], "kwargs": {"indices_offset":2, "fields_and_values": CVP_DATA_VALID_FIELD_VALUES, "delimiter": ","}},] }, } diff --git a/django/api/services/spreadsheet_uploader_prep.py b/django/api/services/spreadsheet_uploader_prep.py index 92ce2b71..ed30de8d 100644 --- a/django/api/services/spreadsheet_uploader_prep.py +++ b/django/api/services/spreadsheet_uploader_prep.py @@ -358,12 +358,14 @@ def validate_field_values(df, *columns, **kwargs): invalid_values = [] result = {} + delimiter = kwargs.get("delimiter") for column in df.columns: if column in allowed_values: indices = [] series = df[column] for index, value in series.items(): - items = [item.strip() for item in value.split(",")] + if delimiter is not None: + items = [item.strip() for item in value.split(delimiter)] for item in items: if str(item).upper() not in (valid.upper() for valid in allowed_values[column]) and item != '' and item is not None and not pd.isna(item):