manager: fix event index when CSV import file has header (#79845)
gitea/chrono/pipeline/head This commit looks good
Details
gitea/chrono/pipeline/head This commit looks good
Details
This commit is contained in:
parent
c1dd25d2c7
commit
95618bd475
|
@ -1207,9 +1207,11 @@ class ImportEventsForm(forms.Form):
|
|||
|
||||
def clean_events_csv_file(self):
|
||||
class ValidationErrorWithOrdinal(ValidationError):
|
||||
line_offset = 1
|
||||
|
||||
def __init__(self, message, event_no):
|
||||
super().__init__(message)
|
||||
self.message = format_html(message, event_no=mark_safe(ordinal(event_no + 1)))
|
||||
self.message = format_html(message, event_no=mark_safe(ordinal(event_no + self.line_offset)))
|
||||
|
||||
exclude_from_validation = ['desk', 'meeting_type', 'primary_event']
|
||||
|
||||
|
@ -1247,6 +1249,7 @@ class ImportEventsForm(forms.Form):
|
|||
if len(csvline) < 3:
|
||||
raise ValidationErrorWithOrdinal(_('Invalid file format. ({event_no} event)'), i)
|
||||
if i == 0 and csvline[0].strip('#') in ('date', 'Date', _('date'), _('Date')):
|
||||
ValidationErrorWithOrdinal.line_offset = 0
|
||||
continue
|
||||
|
||||
# label needed to generate a slug
|
||||
|
|
|
@ -808,6 +808,10 @@ def test_import_events(app, admin_user):
|
|||
resp = resp.form.submit(status=200)
|
||||
assert 'Invalid file format.' in resp.text
|
||||
|
||||
resp.form['events_csv_file'] = Upload('t.csv', b'date,time,etc.\n2016-14-16,18:00,10', 'text/csv')
|
||||
resp = resp.form.submit(status=200)
|
||||
assert 'Invalid file format. (date/time format, 1st event)' in resp.text
|
||||
|
||||
resp.form['events_csv_file'] = Upload('t.csv', b'2016-14-16,18:00,10', 'text/csv')
|
||||
resp = resp.form.submit(status=200)
|
||||
assert 'Invalid file format. (date/time format, 1st event)' in resp.text
|
||||
|
|
Loading…
Reference in New Issue