Skip to content

Commit

Permalink
Added logic to include the expected values for restricted fields
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianForeman committed Sep 20, 2024
1 parent 78a8e20 commit 0058f1f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion django/api/services/spreadsheet_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def transform_data(
errors_and_warnings[column] = {}
if "Empty Value" not in errors_and_warnings[column]:
errors_and_warnings[column]["Empty Value"] = {
"Expected Type": "Expected value where there isn't one.",
"Expected Type": "Cells in this column cannot be blank.",
"Rows": [],
"Severity": "Error"
}
Expand Down
9 changes: 6 additions & 3 deletions django/api/services/spreadsheet_uploader_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ def email_validator(df, *columns, **kwargs):

def validate_field_values(df, *columns, **kwargs):
allowed_values = kwargs.get("fields_and_values")

invalid_values = []

result = {}
for column in df.columns:
if column in allowed_values:
Expand All @@ -325,10 +326,12 @@ def validate_field_values(df, *columns, **kwargs):
for index, value in series.items():
if str(value).upper() not in (item.upper() for item in allowed_values[column]) and value != '' and value is not None and not pd.isna(value):
indices.append(index + kwargs.get("indices_offset", 0))
if str(value) not in invalid_values:
invalid_values.append(str(value))
if indices:
result[column] = {
"Invalid Values": {
"Expected Type": "The following rows only allow specific values",
', '.join(invalid_values) + " - is not in the list of expected values": {
"Expected Type": ', '.join(allowed_values[column]),
"Rows": indices,
"Severity": "Error"
}
Expand Down

0 comments on commit 0058f1f

Please sign in to comment.