Projet

Général

Profil

0001-manager-keep-multilines-when-importing-CSV-44858.patch

Lauréline Guérin, 10 juillet 2020 09:17

Télécharger (2,14 ko)

Voir les différences:

Subject: [PATCH] manager: keep multilines when importing CSV (#44858)

 chrono/manager/forms.py | 3 ++-
 tests/test_manager.py   | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)
chrono/manager/forms.py
24 24
from django.core.exceptions import FieldDoesNotExist
25 25
from django.forms import ValidationError
26 26
from django.utils.encoding import force_text
27
from django.utils.six import StringIO
27 28
from django.utils.timezone import make_aware
28 29
from django.utils.translation import ugettext_lazy as _
29 30

  
......
296 297

  
297 298
        events = []
298 299
        slugs = set()
299
        for i, csvline in enumerate(csv.reader(content.splitlines(), dialect=dialect)):
300
        for i, csvline in enumerate(csv.reader(StringIO(content), dialect=dialect)):
300 301
            if not csvline:
301 302
                continue
302 303
            if len(csvline) < 3:
tests/test_manager.py
1327 1327
    Event.objects.all().delete()
1328 1328
    resp = app.get('/manage/agendas/%s/import-events' % agenda.id, status=200)
1329 1329
    resp.form['events_csv_file'] = Upload(
1330
        't.csv', b'2016-09-16,18:00,10,5,label,slug,description,pricing,url,2016-10-16', 'text/csv'
1330
        't.csv', b'2016-09-16,18:00,10,5,label,slug,"description\nfoobar",pricing,url,2016-10-16', 'text/csv'
1331 1331
    )
1332 1332
    resp = resp.form.submit(status=302)
1333 1333
    assert Event.objects.count() == 1
1334 1334
    event = Event.objects.get()
1335
    assert event.description == 'description'
1335
    assert event.description == 'description\nfoobar'
1336 1336
    assert event.pricing == 'pricing'
1337 1337
    assert event.url == 'url'
1338 1338
    assert event.publication_date == datetime.date(2016, 10, 16)
1339
-