Projet

Général

Profil

0001-manager-ignore-BOM-when-importing-CSV-44170.patch

Frédéric Péters, 17 juin 2020 14:30

Télécharger (2,13 ko)

Voir les différences:

Subject: [PATCH] manager: ignore BOM when importing CSV (#44170)

 chrono/manager/forms.py |  2 +-
 tests/test_manager.py   | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
chrono/manager/forms.py
280 280
        if b'\0' in content:
281 281
            raise ValidationError(_('Invalid file format.'))
282 282

  
283
        for charset in ('utf-8', 'iso-8859-15'):
283
        for charset in ('utf-8-sig', 'iso-8859-15'):
284 284
            try:
285 285
                content = content.decode(charset)
286 286
                break
tests/test_manager.py
1 1
# -*- coding: utf-8 -*-
2 2

  
3 3
from __future__ import unicode_literals
4
import codecs
4 5
import copy
5 6
import datetime
6 7
import json
......
1238 1239
    assert Event.objects.all()[0].label == u'éléphant'
1239 1240
    Event.objects.all().delete()
1240 1241

  
1242
    # BOM
1243
    resp = app.get('/manage/agendas/%s/import-events' % agenda.id, status=200)
1244
    resp.form['events_csv_file'] = Upload(
1245
        't.csv', codecs.BOM_UTF8 + u'2016-09-16,18:00,10,5,éléphant'.encode('utf-8'), 'text/csv'
1246
    )
1247
    resp = resp.form.submit(status=302)
1248
    assert Event.objects.count() == 1
1249
    assert Event.objects.all()[0].start_datetime == make_aware(datetime.datetime(2016, 9, 16, 18, 0))
1250
    assert Event.objects.all()[0].places == 10
1251
    assert Event.objects.all()[0].waiting_list_places == 5
1252
    assert Event.objects.all()[0].label == u'éléphant'
1253
    Event.objects.all().delete()
1254

  
1241 1255
    resp = app.get('/manage/agendas/%s/import-events' % agenda.id, status=200)
1242 1256
    resp.form['events_csv_file'] = Upload(
1243 1257
        't.csv', u'2016-09-16,18:00,10,5,éléphant'.encode('iso-8859-15'), 'text/csv'
1244
-