manager: ignore BOM when importing CSV (#44170)
This commit is contained in:
parent
5616ee60a0
commit
3ba233792d
|
@ -280,7 +280,7 @@ class ImportEventsForm(forms.Form):
|
|||
if b'\0' in content:
|
||||
raise ValidationError(_('Invalid file format.'))
|
||||
|
||||
for charset in ('utf-8', 'iso-8859-15'):
|
||||
for charset in ('utf-8-sig', 'iso-8859-15'):
|
||||
try:
|
||||
content = content.decode(charset)
|
||||
break
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import codecs
|
||||
import copy
|
||||
import datetime
|
||||
import json
|
||||
|
@ -1270,6 +1271,19 @@ def test_import_events(app, admin_user):
|
|||
assert Event.objects.all()[0].label == u'éléphant'
|
||||
Event.objects.all().delete()
|
||||
|
||||
# BOM
|
||||
resp = app.get('/manage/agendas/%s/import-events' % agenda.id, status=200)
|
||||
resp.form['events_csv_file'] = Upload(
|
||||
't.csv', codecs.BOM_UTF8 + u'2016-09-16,18:00,10,5,éléphant'.encode('utf-8'), 'text/csv'
|
||||
)
|
||||
resp = resp.form.submit(status=302)
|
||||
assert Event.objects.count() == 1
|
||||
assert Event.objects.all()[0].start_datetime == make_aware(datetime.datetime(2016, 9, 16, 18, 0))
|
||||
assert Event.objects.all()[0].places == 10
|
||||
assert Event.objects.all()[0].waiting_list_places == 5
|
||||
assert Event.objects.all()[0].label == u'éléphant'
|
||||
Event.objects.all().delete()
|
||||
|
||||
resp = app.get('/manage/agendas/%s/import-events' % agenda.id, status=200)
|
||||
resp.form['events_csv_file'] = Upload(
|
||||
't.csv', u'2016-09-16,18:00,10,5,éléphant'.encode('iso-8859-15'), 'text/csv'
|
||||
|
|
Loading…
Reference in New Issue