From 42c55f5521657f3d0be5379150354f992231fbbc Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Fri, 25 May 2018 14:36:14 +0200 Subject: [PATCH] Also test csv file from upload extension --- stages/views.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/stages/views.py b/stages/views.py index 8243c92..e8ffd61 100644 --- a/stages/views.py +++ b/stages/views.py @@ -286,8 +286,13 @@ class ImportViewBase(FormView): def form_valid(self, form): upfile = form.cleaned_data['upload'] + is_csv = ( + upfile.name.endswith('.csv') or + 'csv' in upfile.content_type or + upfile.content_type == 'text/plain' + ) try: - if 'csv' in upfile.content_type or upfile.content_type == 'text/plain': + if is_csv: # Reopen the file in text mode upfile = open(upfile.temporary_file_path(), mode='r', encoding='utf-8-sig') imp_file = CSVImportedFile(File(upfile)) @@ -298,7 +303,7 @@ class ImportViewBase(FormView): except Exception as e: if settings.DEBUG: raise - messages.error(self.request, _("The import failed. Error message: %s") % e) + messages.error(self.request, "L'importation a échoué. Erreur: %s (content-type: %s)" % (e, upfile.content_type)) else: non_fatal_errors = stats.get('errors', []) if 'created' in stats: