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-07-21 15:07:41 +0200
commit5499e558a541a0c8740d608dc4446f64ebe774c6 (patch)
tree28fbac26740b4f2ea19a0261422deb7e46f7af65 /ishtar_common/data_importer.py
parent62b34d0afb55a5c5c7bc1da22f0c0d293ee3936d (diff)
downloadIshtar-5499e558a541a0c8740d608dc4446f64ebe774c6.tar.bz2
Ishtar-5499e558a541a0c8740d608dc4446f64ebe774c6.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 4259e1b8a..7df66a672 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')