summaryrefslogtreecommitdiff
path: root/ishtar_common/models_imports.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2023-09-21 16:35:51 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2024-04-16 16:38:32 +0200
commit27eac8dc6cf0e96f78edfe4e09845e454fb6d510 (patch)
tree9eed227b29bb9accefa2f4d9bef084bf9711dfca /ishtar_common/models_imports.py
parentc2f41df8521a75a96f5d6a0960e993b8d86bed80 (diff)
downloadIshtar-27eac8dc6cf0e96f78edfe4e09845e454fb6d510.tar.bz2
Ishtar-27eac8dc6cf0e96f78edfe4e09845e454fb6d510.zip
⚡️ imports: prevent unecessary copy
Diffstat (limited to 'ishtar_common/models_imports.py')
-rw-r--r--ishtar_common/models_imports.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/ishtar_common/models_imports.py b/ishtar_common/models_imports.py
index 78398ea1a..ca0a38832 100644
--- a/ishtar_common/models_imports.py
+++ b/ishtar_common/models_imports.py
@@ -1421,12 +1421,16 @@ class BaseImport(models.Model):
self.state = state
self.save() # only save if no save previously
+ def get_imported_images(self):
+ return self.imported_images
+
def save(self, *args, **kwargs):
super().save(*args, **kwargs)
if (
self.state == "AC"
and not getattr(self, "_archive_pending", False)
and not self.archive_file
+ and not getattr(self, "group", False)
):
self._archive()
@@ -1618,7 +1622,7 @@ class ImportGroup(BaseImport):
f.path = w_filename
setattr(current_import, attr, f)
current_import.save()
- getattr(current_import, attr).name = w_filename
+ getattr(current_import, attr).name = w_filename[len(settings.MEDIA_ROOT):]
current_import.save()
os.remove(self.archive_file.path)
self.refresh_from_db()
@@ -1694,12 +1698,11 @@ class ImportGroup(BaseImport):
except FileNotFoundError:
pass
setattr(sub_import, attr, None)
+ sub_import.state = "AC"
+ sub_import.save()
self.save()
self._archive_pending = False
- def archive(self):
- super().archive()
- self.imports.update(state="AC")
def get_all_imported(self):
imported = []
@@ -1725,10 +1728,10 @@ class ImportGroup(BaseImport):
imported_images.name = self.imported_images.name.split(os.sep)[-1]
for import_type_relation in self.importer_type.importer_types.all():
- import_type = import_type_relation.importer_type
+ importer_type = import_type_relation.importer_type
imp = Import.objects.create(
name=name,
- importer_type=import_type,
+ importer_type=importer_type,
group=self,
)
imports.append(imp)
@@ -1737,7 +1740,7 @@ class ImportGroup(BaseImport):
if imported_file:
imp.imported_file = imported_file
modified = True
- if import_type.archive_required and imported_images:
+ if importer_type.archive_required and imported_images:
imp.imported_images = imported_images
modified = True
if modified:
@@ -1841,6 +1844,12 @@ class Import(BaseImport):
TargetKey.objects.filter(associated_import=self, is_set=False).count()
)
+ def get_imported_images(self):
+ if not self.group:
+ return self.imported_images
+ if self.importer_type.archive_required:
+ return self.group.imported_images
+
@property
def errors(self):
if not self.error_file: