Projet

Général

Profil

0001-manager-duration-in-csv-event-import-44775.patch

Lauréline Guérin, 09 juillet 2020 16:11

Télécharger (4,8 ko)

Voir les différences:

Subject: [PATCH] manager: duration in csv event import (#44775)

 chrono/manager/forms.py                            |  6 ++++++
 .../templates/chrono/manager_sample_events.txt     |  4 ++--
 tests/test_manager.py                              | 14 ++++++++++++--
 3 files changed, 20 insertions(+), 4 deletions(-)
chrono/manager/forms.py
358 358
                else:
359 359
                    raise ValidationError(_('Invalid file format. (date format, line %d)') % (i + 1))
360 360

  
361
            if len(csvline) >= 11 and csvline[10]:  # duration is optional
362
                try:
363
                    event.duration = int(csvline[10])
364
                except ValueError:
365
                    raise ValidationError(_('Invalid file format. (duration, line %d)') % (i + 1))
366

  
361 367
            try:
362 368
                event.full_clean(exclude=exclude)
363 369
            except ValidationError as e:
chrono/manager/templates/chrono/manager_sample_events.txt
1
{% 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' %}
2
{{ 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" }}
1
{% 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' %}
2
{{ 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
tests/test_manager.py
1316 1316
    # additional optional attributes
1317 1317
    Event.objects.all().delete()
1318 1318
    resp = app.get('/manage/agendas/%s/import-events' % agenda.id, status=200)
1319
    resp.form['events_csv_file'] = Upload('t.csv', b'2016-09-16,18:00,10,5,label,slug,,,,', 'text/csv')
1319
    resp.form['events_csv_file'] = Upload('t.csv', b'2016-09-16,18:00,10,5,label,slug,,,,,', 'text/csv')
1320 1320
    resp = resp.form.submit(status=302)
1321 1321
    assert Event.objects.count() == 1
1322 1322
    event = Event.objects.get()
......
1324 1324
    assert event.pricing == ''
1325 1325
    assert event.url == ''
1326 1326
    assert event.publication_date is None
1327
    assert event.duration is None
1327 1328
    Event.objects.all().delete()
1328 1329
    resp = app.get('/manage/agendas/%s/import-events' % agenda.id, status=200)
1329 1330
    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'
1331
        't.csv', b'2016-09-16,18:00,10,5,label,slug,description,pricing,url,2016-10-16,90', 'text/csv'
1331 1332
    )
1332 1333
    resp = resp.form.submit(status=302)
1333 1334
    assert Event.objects.count() == 1
......
1336 1337
    assert event.pricing == 'pricing'
1337 1338
    assert event.url == 'url'
1338 1339
    assert event.publication_date == datetime.date(2016, 10, 16)
1340
    assert event.duration == 90
1339 1341

  
1340 1342
    # publication date bad format
1341 1343
    resp = app.get('/manage/agendas/%s/import-events' % agenda.id, status=200)
......
1345 1347
    resp = resp.form.submit(status=200)
1346 1348
    assert 'Invalid file format. (date format' in resp.text
1347 1349

  
1350
    # duration bad format
1351
    resp = app.get('/manage/agendas/%s/import-events' % agenda.id, status=200)
1352
    resp.form['events_csv_file'] = Upload(
1353
        't.csv', b'2016-09-16,18:00,10,5,label,slug,description,pricing,url,2016-09-16,foobar', 'text/csv'
1354
    )
1355
    resp = resp.form.submit(status=200)
1356
    assert 'Invalid file format. (duration' in resp.text
1357

  
1348 1358
    # import events with empty slugs
1349 1359
    Event.objects.all().delete()
1350 1360
    resp = app.get('/manage/agendas/%s/import-events' % agenda.id, status=200)
1351
-