diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-09-15 18:46:41 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2024-04-16 16:38:32 +0200 |
commit | 5ec78fa85dbb6b7ec7d286827b6e32f82c489b3e (patch) | |
tree | f4f98c3ef9923df42ff579fbc9b71c807f26716e /ishtar_common/migrations | |
parent | b1c4e814bdb7ded9314b8d5337fa5841c737d32d (diff) | |
download | Ishtar-5ec78fa85dbb6b7ec7d286827b6e32f82c489b3e.tar.bz2 Ishtar-5ec78fa85dbb6b7ec7d286827b6e32f82c489b3e.zip |
♻️ refactoring and optimisation: manage defaults like pre_importer_values - add an explicit field for required value to apply defaults
Diffstat (limited to 'ishtar_common/migrations')
-rw-r--r-- | ishtar_common/migrations/0230_auto_20230918_1655.py (renamed from ishtar_common/migrations/0230_auto_20230912_1832.py) | 12 | ||||
-rw-r--r-- | ishtar_common/migrations/0231_default_mandatory_keys.py | 38 |
2 files changed, 49 insertions, 1 deletions
diff --git a/ishtar_common/migrations/0230_auto_20230912_1832.py b/ishtar_common/migrations/0230_auto_20230918_1655.py index 649e0dccb..76fba744c 100644 --- a/ishtar_common/migrations/0230_auto_20230912_1832.py +++ b/ishtar_common/migrations/0230_auto_20230918_1655.py @@ -1,4 +1,4 @@ -# Generated by Django 2.2.24 on 2023-09-12 18:32 +# Generated by Django 2.2.24 on 2023-09-18 16:55 import django.core.validators from django.db import migrations, models @@ -41,6 +41,11 @@ class Migration(migrations.Migration): field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='imports', to='ishtar_common.Import', verbose_name='Next import'), ), migrations.AddField( + model_name='importerdefault', + name='required_fields', + field=models.CharField(blank=True, default='', help_text='Theses defaults values only apply if the designated fields are not empty. Use the "__" notation to pass between models.Leave empty to always apply.', max_length=500, verbose_name='Required fields'), + ), + migrations.AddField( model_name='importertype', name='archive_required', field=models.BooleanField(default=False, verbose_name='Archive required'), @@ -71,6 +76,11 @@ class Migration(migrations.Migration): field=models.SmallIntegerField(default=1, help_text='Column number in the table. Put 0 or negative number for pre-importer field.', verbose_name='Column number'), ), migrations.AlterField( + model_name='importerdefault', + name='target', + field=models.CharField(help_text='The target of the default values. Can be set to empty with "-". Use the "__" notation to pass between models.', max_length=500, verbose_name='Target'), + ), + migrations.AlterField( model_name='ishtarsiteprofile', name='account_naming_style', field=models.CharField(choices=[('NF', 'name.firstname'), ('FN', 'firstname.name')], default='FN', max_length=2, verbose_name='Naming style for accounts'), diff --git a/ishtar_common/migrations/0231_default_mandatory_keys.py b/ishtar_common/migrations/0231_default_mandatory_keys.py new file mode 100644 index 000000000..4c5e2ea35 --- /dev/null +++ b/ishtar_common/migrations/0231_default_mandatory_keys.py @@ -0,0 +1,38 @@ +# Generated by Django 2.2.24 on 2023-09-18 17:05 + +from django.db import migrations + +EXCLUDE_LIST = [ + "-", + "auto_external_id", + "spatial_reference_system", + "public_domain", +] + +FULL_COPY_LIST = [ + "scientist__attached_to", +] + + +def migrate(apps, __): + ImporterDefault = apps.get_model('ishtar_common', 'ImporterDefault') + for default in ImporterDefault.objects.all(): + if default.target not in EXCLUDE_LIST: + req = default.target + if req not in FULL_COPY_LIST: + req = req.split("__")[0] + if req.endswith("_type") or req.endswith("_types"): + continue + default.required_fields = req + default.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0230_auto_20230918_1655'), + ] + + operations = [ + migrations.RunPython(migrate), + ] |