From 9d0bb012a463c7ce7805efd25888f938bb7d8867 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 --- archaeological_finds/tests/notices-panier.odt | Bin 0 -> 55063 bytes .../migrations/0212_auto_20210219_1408.py | 46 ------------------- .../migrations/0212_auto_20210222_1334.py | 51 +++++++++++++++++++++ ishtar_common/models_imports.py | 7 ++- 4 files changed, 56 insertions(+), 48 deletions(-) create mode 100644 archaeological_finds/tests/notices-panier.odt delete mode 100644 ishtar_common/migrations/0212_auto_20210219_1408.py create mode 100644 ishtar_common/migrations/0212_auto_20210222_1334.py diff --git a/archaeological_finds/tests/notices-panier.odt b/archaeological_finds/tests/notices-panier.odt new file mode 100644 index 000000000..71b248e79 Binary files /dev/null and b/archaeological_finds/tests/notices-panier.odt differ diff --git a/ishtar_common/migrations/0212_auto_20210219_1408.py b/ishtar_common/migrations/0212_auto_20210219_1408.py deleted file mode 100644 index 25d49e75f..000000000 --- a/ishtar_common/migrations/0212_auto_20210219_1408.py +++ /dev/null @@ -1,46 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.27 on 2021-02-19 14:08 -from __future__ import unicode_literals - -from django.db import migrations, models -import ishtar_common.models - - -class Migration(migrations.Migration): - - dependencies = [ - ('ishtar_common', '0211_auto_20210111_1321'), - ] - - operations = [ - migrations.AddField( - model_name='import', - name='archive_file', - field=models.FileField(blank=True, help_text='La taille maximale supportée pour le fichier est de 100 Mo.', max_length=255, null=True, upload_to='upload/imports/%Y/%m/', verbose_name='Archive file'), - ), - migrations.AddField( - model_name='ishtarsiteprofile', - name='delete_image_zip_on_archive', - field=models.BooleanField(default=False, verbose_name='Import - Delete image/document zip on archive'), - ), - migrations.AlterField( - model_name='historicalorganization', - name='grammatical_gender', - field=models.CharField(blank=True, choices=[('M', 'Male'), ('F', 'Female'), ('N', 'Neutral')], default='', help_text=ishtar_common.models.documentation_get_gender_values, max_length=1, verbose_name='Grammatical gender'), - ), - migrations.AlterField( - model_name='organization', - name='grammatical_gender', - field=models.CharField(blank=True, choices=[('M', 'Male'), ('F', 'Female'), ('N', 'Neutral')], default='', help_text=ishtar_common.models.documentation_get_gender_values, max_length=1, verbose_name='Grammatical gender'), - ), - migrations.AlterField( - model_name='organizationtype', - name='grammatical_gender', - field=models.CharField(blank=True, choices=[('M', 'Male'), ('F', 'Female'), ('N', 'Neutral')], default='', help_text=ishtar_common.models.documentation_get_gender_values, max_length=1, verbose_name='Grammatical gender'), - ), - migrations.AlterField( - model_name='titletype', - name='grammatical_gender', - field=models.CharField(blank=True, choices=[('M', 'Male'), ('F', 'Female'), ('N', 'Neutral')], default='', help_text=ishtar_common.models.documentation_get_gender_values, max_length=1, verbose_name='Grammatical gender'), - ), - ] diff --git a/ishtar_common/migrations/0212_auto_20210222_1334.py b/ishtar_common/migrations/0212_auto_20210222_1334.py new file mode 100644 index 000000000..703b58f2b --- /dev/null +++ b/ishtar_common/migrations/0212_auto_20210222_1334.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.27 on 2021-02-22 13:34 +from __future__ import unicode_literals + +from django.db import migrations, models +import ishtar_common.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0211_auto_20210111_1321'), + ] + + operations = [ + migrations.AddField( + model_name='import', + name='archive_file', + field=models.FileField(blank=True, help_text='La taille maximale supportée pour le fichier est de 100 Mo.', max_length=255, null=True, upload_to='upload/imports/%Y/%m/', verbose_name='Archive file'), + ), + migrations.AddField( + model_name='ishtarsiteprofile', + name='delete_image_zip_on_archive', + field=models.BooleanField(default=False, verbose_name='Import - Delete image/document zip on archive'), + ), + migrations.AlterField( + model_name='historicalorganization', + name='grammatical_gender', + field=models.CharField(blank=True, choices=[('M', 'Male'), ('F', 'Female'), ('N', 'Neutral')], default='', help_text=ishtar_common.models.documentation_get_gender_values, max_length=1, verbose_name='Grammatical gender'), + ), + migrations.AlterField( + model_name='import', + name='imported_file', + field=models.FileField(blank=True, help_text='La taille maximale supportée pour le fichier est de 100 Mo.', max_length=220, null=True, upload_to='upload/imports/%Y/%m/', verbose_name='Imported file'), + ), + migrations.AlterField( + model_name='organization', + name='grammatical_gender', + field=models.CharField(blank=True, choices=[('M', 'Male'), ('F', 'Female'), ('N', 'Neutral')], default='', help_text=ishtar_common.models.documentation_get_gender_values, max_length=1, verbose_name='Grammatical gender'), + ), + migrations.AlterField( + model_name='organizationtype', + name='grammatical_gender', + field=models.CharField(blank=True, choices=[('M', 'Male'), ('F', 'Female'), ('N', 'Neutral')], default='', help_text=ishtar_common.models.documentation_get_gender_values, max_length=1, verbose_name='Grammatical gender'), + ), + migrations.AlterField( + model_name='titletype', + name='grammatical_gender', + field=models.CharField(blank=True, choices=[('M', 'Male'), ('F', 'Female'), ('N', 'Neutral')], default='', help_text=ishtar_common.models.documentation_get_gender_values, max_length=1, verbose_name='Grammatical gender'), + ), + ] 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