summaryrefslogtreecommitdiff
path: root/ishtar_common
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
commit9945b83c5184a1c794f0e8b7ae854ff1c6a812b0 (patch)
tree6c93a30f83278a7c826a26f105ebf588a067ee20 /ishtar_common
parentd61fdfc2c6edda04b8863c6d10ed032933f50dbf (diff)
downloadIshtar-9945b83c5184a1c794f0e8b7ae854ff1c6a812b0.tar.bz2
Ishtar-9945b83c5184a1c794f0e8b7ae854ff1c6a812b0.zip
Imports: CSV check fix encoding check
Diffstat (limited to 'ishtar_common')
-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)