From 5c9701f05ddaba63d957f1973652be545a57bea0 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 22 Feb 2021 13:35:45 +0100 Subject: Imports: imported file not mandatory (when zipped can be null) - do not raise error if media file is missing --- ishtar_common/models_imports.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'ishtar_common/models_imports.py') diff --git a/ishtar_common/models_imports.py b/ishtar_common/models_imports.py index 5a3af1a05..7462f55be 100644 --- a/ishtar_common/models_imports.py +++ b/ishtar_common/models_imports.py @@ -939,7 +939,7 @@ class Import(models.Model): importer_type = models.ForeignKey(ImporterType) imported_file = models.FileField( _("Imported file"), upload_to="upload/imports/%Y/%m/", max_length=220, - help_text=max_size_help()) + help_text=max_size_help(), blank=True, null=True) imported_images = models.FileField( _("Associated images (zip file)"), upload_to="upload/imports/%Y/%m/", blank=True, null=True, max_length=220, help_text=max_size_help()) @@ -1438,7 +1438,10 @@ class Import(models.Model): for attr in file_attr: file_field = getattr(self, attr) if file_field: - os.remove(file_field.path) + try: + os.remove(file_field.path) + except FileNotFoundError: + pass setattr(self, attr, None) self.save() self._archive_pending = False -- cgit v1.2.3