summaryrefslogtreecommitdiff
path: root/ishtar_common/forms_common.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2022-08-05 13:24:20 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-12-12 12:23:17 +0100
commit3c743fcb4de71ea3406ded002a77fe811e13b7cf (patch)
tree6c93a30f83278a7c826a26f105ebf588a067ee20 /ishtar_common/forms_common.py
parent722dcb00774ca1f7dfb38d0941ec0047e3fdb661 (diff)
downloadIshtar-3c743fcb4de71ea3406ded002a77fe811e13b7cf.tar.bz2
Ishtar-3c743fcb4de71ea3406ded002a77fe811e13b7cf.zip
Imports: CSV check fix encoding check
Diffstat (limited to 'ishtar_common/forms_common.py')
-rw-r--r--ishtar_common/forms_common.py24
1 files changed, 11 insertions, 13 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py
index 2ec6822b8..e4f432b4f 100644
--- a/ishtar_common/forms_common.py
+++ b/ishtar_common/forms_common.py
@@ -273,24 +273,22 @@ class NewImportForm(BaseImportForm):
raise forms.ValidationError(
_("\"Associated images\" field must be a valid zip file.")
)
-
- return data
-
- def clean_imported_file(self):
- value = self.cleaned_data.get("imported_file", None)
- if value:
+ imported_file = self.cleaned_data.get("imported_file", None)
+ encoding = self.cleaned_data.get("encoding", None)
+ if imported_file and encoding:
try:
- assert value.name.lower().endswith(".csv")
- value.seek(0)
- reader = csv.reader(StringIO(value.read().decode('utf-8')))
+ assert imported_file.name.lower().endswith(".csv")
+ imported_file.seek(0)
+ reader = csv.reader(StringIO(imported_file.read().decode(encoding)))
for __ in reader:
break
- value.seek(0)
- except (AssertionError, UnicodeDecodeError):
+ imported_file.seek(0)
+ except (AssertionError, UnicodeDecodeError) as e:
raise forms.ValidationError(
- _("This is not a valid CSV file.")
+ _("This is not a valid CSV file. Check file format and encoding.")
)
- return value
+
+ return data
def clean_imported_images_link(self):
value = self.cleaned_data.get("imported_images_link", None)