diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-09-21 16:35:51 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2024-02-05 10:51:52 +0100 |
commit | 9737bc047a8f013d3556a627a7052b5aac08c692 (patch) | |
tree | 1b4ad38566c0654b0a8b175b2379fd568eb7318c /ishtar_common/models_imports.py | |
parent | 82b4bb60d9b92d9754d87ea24f87cf68b55826a5 (diff) | |
download | Ishtar-9737bc047a8f013d3556a627a7052b5aac08c692.tar.bz2 Ishtar-9737bc047a8f013d3556a627a7052b5aac08c692.zip |
⚡️ imports: prevent unecessary copy
Diffstat (limited to 'ishtar_common/models_imports.py')
-rw-r--r-- | ishtar_common/models_imports.py | 23 |
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: |