manager: validate imported events (#35011)
This commit is contained in:
parent
ec54a71325
commit
7142c0eb42
|
@ -221,6 +221,16 @@ class ImportEventsForm(forms.Form):
|
|||
raise ValidationError(_('Invalid file format. (number of places in waiting list, line %d)') % (i+1))
|
||||
if len(csvline) >= 5:
|
||||
event.label = ' '.join([force_text(x) for x in csvline[4:]])
|
||||
try:
|
||||
event.full_clean(exclude=['agenda', 'desk', 'meeting_type'])
|
||||
except ValidationError as e:
|
||||
errors = [
|
||||
_('Invalid file format. (%(label)s: %(errors)s, line %(line)d)') % {
|
||||
'label': label,
|
||||
'errors': u', '.join(field_errors),
|
||||
'line': i + 1
|
||||
} for label, field_errors in e.message_dict.items()]
|
||||
raise ValidationError(errors)
|
||||
events.append(event)
|
||||
self.events = events
|
||||
|
||||
|
|
|
@ -553,6 +553,10 @@ def test_import_events(app, admin_user):
|
|||
resp = resp.form.submit(status=200)
|
||||
assert 'Invalid file format. (number of places in waiting list,' in resp.text
|
||||
|
||||
resp.form['events_csv_file'] = Upload('t.csv', b'2016-09-16,18:00,10,5,' + b'x' * 151, 'text/csv')
|
||||
resp = resp.form.submit(status=200)
|
||||
assert 'Invalid file format. (label: Ensure this value has at most 150' in resp.text
|
||||
|
||||
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', 'text/csv')
|
||||
resp = resp.form.submit(status=302)
|
||||
|
|
Loading…
Reference in New Issue