Only process CSV files when they are correctly read

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello 2023-04-08 17:33:01 +02:00
parent bcf4e294e0
commit 80cfe874f5
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 1 additions and 2 deletions

View File

@ -261,12 +261,11 @@ class UploadNotesForm(forms.Form):
with file:
try:
csvfile = csv.reader(StringIO(file.read().decode()))
self.process(csvfile, cleaned_data)
except UnicodeDecodeError:
self.add_error('file', _("This file contains non-UTF-8 content. "
"Please send your sheet as a CSV file."))
self.process(csvfile, cleaned_data)
return cleaned_data
def process(self, csvfile: Iterable[str], cleaned_data: dict):