summaryrefslogtreecommitdiff
path: root/ishtar_common/data_importer.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2025-08-20 15:42:38 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2025-10-15 19:32:59 +0200
commit7efe436fd9b794ed585a675bf0cbaf9ff4c8464d (patch)
tree7ead31f9d396e4202593e43c56e197ff2e84cfdd /ishtar_common/data_importer.py
parent22089564f871cb265646e878291fecd423edf188 (diff)
downloadIshtar-7efe436fd9b794ed585a675bf0cbaf9ff4c8464d.tar.bz2
Ishtar-7efe436fd9b794ed585a675bf0cbaf9ff4c8464d.zip
🐛 fix unclosed file
Diffstat (limited to 'ishtar_common/data_importer.py')
-rw-r--r--ishtar_common/data_importer.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py
index 253cd593e..a35a74620 100644
--- a/ishtar_common/data_importer.py
+++ b/ishtar_common/data_importer.py
@@ -647,7 +647,6 @@ class FileFormater(Formater):
return my_file
def _format_zip(self, value, archive):
- zp = zipfile.ZipFile(archive)
value = value.strip().replace("\\", "/")
items = value.replace("/", "_").split(".")
base_dir = settings.MEDIA_ROOT + "imported"
@@ -656,14 +655,15 @@ class FileFormater(Formater):
filename = base_dir + os.sep + ".".join(items[:-1]) + "." + items[-1]
try:
- with open(filename, "wb") as f:
- with zp.open(value) as z:
- f.write(z.read())
- f = open(filename, "rb")
- my_file = File(f)
- # manually set the file size because of an issue with TempFile
- my_file.size = os.stat(filename).st_size
- return my_file
+ with zipfile.ZipFile(archive) as zp:
+ with open(filename, "wb") as f:
+ with zp.open(value) as z:
+ f.write(z.read())
+ f = open(filename, "rb")
+ my_file = File(f)
+ # manually set the file size because of an issue with TempFile
+ my_file.size = os.stat(filename).st_size
+ return my_file
except KeyError:
raise ValueError(
_('"%(value)s" is not a valid path for the given archive')