1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-22 15:58:24 +02:00

Allow ISO-8859-1 encoding is CSV files

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello
2023-04-10 17:26:55 +02:00
parent 43af14ad77
commit 41e69992c0
2 changed files with 41 additions and 32 deletions

View File

@ -262,10 +262,16 @@ class UploadNotesForm(forms.Form):
file = cleaned_data['file']
with file:
try:
csvfile = csv.reader(StringIO(file.read().decode()))
data: bytes = file.read()
try:
content = data.decode()
except UnicodeDecodeError:
# This is not UTF-8, grrrr
content = data.decode('latin1')
csvfile = csv.reader(StringIO(content))
self.process(csvfile, cleaned_data)
except UnicodeDecodeError:
self.add_error('file', _("This file contains non-UTF-8 content. "
self.add_error('file', _("This file contains non-UTF-8 and non-ISO-8859-1 content. "
"Please send your sheet as a CSV file."))
return cleaned_data
@ -276,7 +282,7 @@ class UploadNotesForm(forms.Form):
pool_size = 0
line_length = 0
for line in csvfile:
line = [s for s in line if s]
line = [s.strip() for s in line if s]
if line and line[0] == 'Problème':
pool_size = len(line) - 1
if pool_size < 3 or pool_size > 5: