summaryrefslogtreecommitdiff
path: root/ishtar_common/data_importer.py
diff options
context:
space:
mode:
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')