From 4519a5a33366b481a335f9382b1c27061a0f23f6 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 16 Jan 2025 13:31:40 -0800 Subject: [PATCH] try again --- app/main/validators.py | 4 ---- app/models/spreadsheet.py | 9 +++++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/app/main/validators.py b/app/main/validators.py index 076e06aea..e1292b959 100644 --- a/app/main/validators.py +++ b/app/main/validators.py @@ -28,10 +28,6 @@ class CsvFileValidator: self.message = message def __call__(self, form, field): - if not Spreadsheet.approves_headers(field.data): - raise ValidationError( - f"{field.data.filename} does not have headers in row 1" - ) if not Spreadsheet.can_handle(field.data.filename): raise ValidationError( "{} is not a spreadsheet that Notify can read".format( diff --git a/app/models/spreadsheet.py b/app/models/spreadsheet.py index 55b1fa2cf..ece8e9b11 100644 --- a/app/models/spreadsheet.py +++ b/app/models/spreadsheet.py @@ -32,9 +32,6 @@ class Spreadsheet: self._csv_data = converted.getvalue() return self._csv_data - @classmethod - def approves_headers(cls, field_data): - raise Exception(f"Field data {field_data}") @classmethod def can_handle(cls, filename): @@ -46,7 +43,11 @@ class Spreadsheet: @staticmethod def normalise_newlines(file_content): - return "\r\n".join(file_content.read().decode("utf-8").splitlines()) + rows = file_content.read().decode("utf-8").splitlines() + if rows.get(0) is None or rows[0] == "": + raise Exception("No header row") + return "\r\n".join(rows) + @classmethod def from_rows(cls, rows, filename=""):