mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2024-12-25 17:42:24 +00:00
Guess the CSV delimiter when uploading a notation sheet
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
parent
ec0419a6d7
commit
0181a1392d
@ -262,7 +262,15 @@ class UploadNotesForm(forms.Form):
|
||||
except UnicodeDecodeError:
|
||||
# This is not UTF-8, grrrr
|
||||
content = data.decode('latin1')
|
||||
csvfile = csv.reader(StringIO(content))
|
||||
for delimiter in [',', ';', '\t', '|']:
|
||||
if content.split('\n')[0].count(delimiter) > 1:
|
||||
break
|
||||
else:
|
||||
self.add_error('file',
|
||||
_("Unable to detect the CSV delimiter. Please use a comma-separated file."))
|
||||
return cleaned_data
|
||||
|
||||
csvfile = csv.reader(StringIO(content), delimiter=delimiter)
|
||||
self.process(csvfile, cleaned_data)
|
||||
except UnicodeDecodeError:
|
||||
self.add_error('file', _("This file contains non-UTF-8 and non-ISO-8859-1 content. "
|
||||
|
Loading…
Reference in New Issue
Block a user