manager: duration in csv event import (#44775)

This commit is contained in:
Lauréline Guérin 2020-07-09 16:10:37 +02:00
parent e5138ec49e
commit f790d2999c
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
3 changed files with 22 additions and 4 deletions

View File

@ -359,6 +359,12 @@ class ImportEventsForm(forms.Form):
else:
raise ValidationError(_('Invalid file format. (date format, line %d)') % (i + 1))
if len(csvline) >= 11 and csvline[10]: # duration is optional
try:
event.duration = int(csvline[10])
except ValueError:
raise ValidationError(_('Invalid file format. (duration, line %d)') % (i + 1))
try:
event.full_clean(exclude=exclude)
except ValidationError as e:

View File

@ -1,2 +1,2 @@
{% load i18n %}{% trans 'date' %},{% trans 'time' %},{% trans 'number of places' %},{% trans 'number of places in waiting list' %},{% trans 'label' %},{% trans 'identifier' %},{% trans 'description' %},{% trans 'pricing' %},{% trans 'URL' %},{% trans 'publication date' %}
{{ some_future_date|date:"Y-m-d" }},{{ some_future_date|date:"H:i" }},15,0,{% trans "example event" as label %}{{ label }},{{ label|slugify }},,,https://www.example.net,{{ some_future_date|date:"Y-m-d" }}
{% load i18n %}{% trans 'date' %},{% trans 'time' %},{% trans 'number of places' %},{% trans 'number of places in waiting list' %},{% trans 'label' %},{% trans 'identifier' %},{% trans 'description' %},{% trans 'pricing' %},{% trans 'URL' %},{% trans 'publication date' %},{% trans 'duration' %}
{{ some_future_date|date:"Y-m-d" }},{{ some_future_date|date:"H:i" }},15,0,{% trans "example event" as label %}{{ label }},{{ label|slugify }},,,https://www.example.net,{{ some_future_date|date:"Y-m-d" }},30

View File

@ -1316,7 +1316,7 @@ def test_import_events(app, admin_user):
# additional optional attributes
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,,,,', 'text/csv')
resp.form['events_csv_file'] = Upload('t.csv', b'2016-09-16,18:00,10,5,label,slug,,,,,', 'text/csv')
resp = resp.form.submit(status=302)
assert Event.objects.count() == 1
event = Event.objects.get()
@ -1324,10 +1324,13 @@ def test_import_events(app, admin_user):
assert event.pricing == ''
assert event.url == ''
assert event.publication_date is None
assert event.duration is None
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\nfoobar",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,90',
'text/csv',
)
resp = resp.form.submit(status=302)
assert Event.objects.count() == 1
@ -1336,6 +1339,7 @@ def test_import_events(app, admin_user):
assert event.pricing == 'pricing'
assert event.url == 'url'
assert event.publication_date == datetime.date(2016, 10, 16)
assert event.duration == 90
# publication date bad format
resp = app.get('/manage/agendas/%s/import-events' % agenda.id, status=200)
@ -1345,6 +1349,14 @@ def test_import_events(app, admin_user):
resp = resp.form.submit(status=200)
assert 'Invalid file format. (date format' in resp.text
# duration bad format
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-09-16,foobar', 'text/csv'
)
resp = resp.form.submit(status=200)
assert 'Invalid file format. (duration' in resp.text
# import events with empty slugs
Event.objects.all().delete()
resp = app.get('/manage/agendas/%s/import-events' % agenda.id, status=200)