From 7c3044f82fac7fee630c488a40fc8eb588cac834 Mon Sep 17 00:00:00 2001 From: Thomas Rusiecki Date: Mon, 11 Nov 2024 14:49:17 -0300 Subject: [PATCH] catching pandas exception --- evidence/forms.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/evidence/forms.py b/evidence/forms.py index a2c0020..83d9e6b 100644 --- a/evidence/forms.py +++ b/evidence/forms.py @@ -130,7 +130,15 @@ class ImportForm(forms.Form): data = self.cleaned_data["file_import"] self.file_name = data.name - df = pd.read_excel(data) + + try: + df = pd.read_excel(data) + except Exception as e: + raise ValidationError( + _("Error on '%(file_name)s': Invalid File"), + params={"file_name": self.file_name} + ) + df.fillna('', inplace=True) data_pd = df.to_dict(orient='index')