From 3bea7f1234c36ac38da4d104ceb4d5a7c53d7757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rene=CC=81=20Ko=CC=88cher?= Date: Fri, 13 Apr 2012 22:02:14 +0200 Subject: [PATCH] Ignore malformed lines in import file (ported from application import). --- openslides/participant/views.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/openslides/participant/views.py b/openslides/participant/views.py index ea1bc176b..ffcc7966f 100644 --- a/openslides/participant/views.py +++ b/openslides/participant/views.py @@ -385,10 +385,15 @@ def user_import(request): dialect = csv.Sniffer().sniff(request.FILES['csvfile'].readline()) dialect = utils.csv_ext.patchup(dialect) 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 if i > 0: - (first_name, last_name, gender, group, type, committee, comment) = line[:7] + try: + (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.last_name = last_name user.first_name = first_name @@ -451,7 +456,8 @@ def user_import(request): messages.warning(request, ungettext('%d application was discarded.', '%d applications were discarded.', applications_removed) % applications_removed) - messages.success(request, _('%d new participants were successfully imported.') % i) + if i > 0: + messages.success(request, _('%d new participants were successfully imported.') % i) return redirect(reverse('user_overview')) except csv.Error: message.error(request, _('Import aborted because of severe errors in the input file.'))