Ignore malformed lines in import file (ported from application import).
This commit is contained in:
parent
113d258b3d
commit
3bea7f1234
|
@ -385,10 +385,15 @@ def user_import(request):
|
||||||
dialect = csv.Sniffer().sniff(request.FILES['csvfile'].readline())
|
dialect = csv.Sniffer().sniff(request.FILES['csvfile'].readline())
|
||||||
dialect = utils.csv_ext.patchup(dialect)
|
dialect = utils.csv_ext.patchup(dialect)
|
||||||
request.FILES['csvfile'].seek(0)
|
request.FILES['csvfile'].seek(0)
|
||||||
for line in csv.reader(request.FILES['csvfile'], dialect=dialect):
|
for (lno, line) in enumerate(csv.reader(request.FILES['csvfile'], dialect=dialect)):
|
||||||
i += 1
|
i += 1
|
||||||
if i > 0:
|
if i > 0:
|
||||||
|
try:
|
||||||
(first_name, last_name, gender, group, type, committee, comment) = line[:7]
|
(first_name, last_name, gender, group, type, committee, comment) = line[:7]
|
||||||
|
except ValueError:
|
||||||
|
messages.error(request, _('Ignoring malformed line %d in import file.') % (lno + 1))
|
||||||
|
i -= 1
|
||||||
|
continue
|
||||||
user = User()
|
user = User()
|
||||||
user.last_name = last_name
|
user.last_name = last_name
|
||||||
user.first_name = first_name
|
user.first_name = first_name
|
||||||
|
@ -451,6 +456,7 @@ def user_import(request):
|
||||||
messages.warning(request, ungettext('%d application was discarded.',
|
messages.warning(request, ungettext('%d application was discarded.',
|
||||||
'%d applications were discarded.', applications_removed) % applications_removed)
|
'%d applications were discarded.', applications_removed) % applications_removed)
|
||||||
|
|
||||||
|
if i > 0:
|
||||||
messages.success(request, _('%d new participants were successfully imported.') % i)
|
messages.success(request, _('%d new participants were successfully imported.') % i)
|
||||||
return redirect(reverse('user_overview'))
|
return redirect(reverse('user_overview'))
|
||||||
except csv.Error:
|
except csv.Error:
|
||||||
|
|
Loading…
Reference in New Issue