summaryrefslogtreecommitdiff
path: root/ishtar_common/data_importer.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2025-03-26 17:27:41 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2025-06-13 18:08:06 +0200
commit08542121281f492511a2724e8f2c98b6c0c77d8f (patch)
tree02c8c796a2dfabaf9ee018470198ee9255a4fe56 /ishtar_common/data_importer.py
parent510b9de8fc74807723d73985a84d494218886db9 (diff)
downloadIshtar-08542121281f492511a2724e8f2c98b6c0c77d8f.tar.bz2
Ishtar-08542121281f492511a2724e8f2c98b6c0c77d8f.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 cf54544fe..941ccc4af 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')