manager: keep multilines when importing CSV (#44858)
This commit is contained in:
parent
3a9fe804ec
commit
a5470be0f9
|
@ -24,6 +24,7 @@ from django.contrib.auth.models import Group
|
|||
from django.core.exceptions import FieldDoesNotExist
|
||||
from django.forms import ValidationError
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.six import StringIO
|
||||
from django.utils.timezone import make_aware
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
@ -296,7 +297,7 @@ class ImportEventsForm(forms.Form):
|
|||
|
||||
events = []
|
||||
slugs = set()
|
||||
for i, csvline in enumerate(csv.reader(content.splitlines(), dialect=dialect)):
|
||||
for i, csvline in enumerate(csv.reader(StringIO(content), dialect=dialect)):
|
||||
if not csvline:
|
||||
continue
|
||||
if len(csvline) < 3:
|
||||
|
|
|
@ -1327,12 +1327,12 @@ def test_import_events(app, admin_user):
|
|||
Event.objects.all().delete()
|
||||
resp = app.get('/manage/agendas/%s/import-events' % agenda.id, status=200)
|
||||
resp.form['events_csv_file'] = Upload(
|
||||
't.csv', b'2016-09-16,18:00,10,5,label,slug,description,pricing,url,2016-10-16', 'text/csv'
|
||||
't.csv', b'2016-09-16,18:00,10,5,label,slug,"description\nfoobar",pricing,url,2016-10-16', 'text/csv'
|
||||
)
|
||||
resp = resp.form.submit(status=302)
|
||||
assert Event.objects.count() == 1
|
||||
event = Event.objects.get()
|
||||
assert event.description == 'description'
|
||||
assert event.description == 'description\nfoobar'
|
||||
assert event.pricing == 'pricing'
|
||||
assert event.url == 'url'
|
||||
assert event.publication_date == datetime.date(2016, 10, 16)
|
||||
|
|
Loading…
Reference in New Issue