diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-09-30 14:06:45 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-10-02 23:15:26 +0200 |
commit | 93ece4d67007e86066726d9b724a7fefa86db68f (patch) | |
tree | 33979ef9781993a9e983b0dcf4b6937fdead229a /archaeological_finds/migrations | |
parent | cacd9f9389b4ccf136cf50191a36b7fbaf4bbded (diff) | |
download | Ishtar-93ece4d67007e86066726d9b724a7fefa86db68f.tar.bz2 Ishtar-93ece4d67007e86066726d9b724a7fefa86db68f.zip |
🗃️ finds - specific tables for recommended treatments
Diffstat (limited to 'archaeological_finds/migrations')
3 files changed, 464 insertions, 0 deletions
diff --git a/archaeological_finds/migrations/0140_recommanded_treatments.py b/archaeological_finds/migrations/0140_recommanded_treatments.py new file mode 100644 index 000000000..250c2bf74 --- /dev/null +++ b/archaeological_finds/migrations/0140_recommanded_treatments.py @@ -0,0 +1,45 @@ +# Generated by Django 2.2.24 on 2025-09-30 11:31 + +import archaeological_finds.models_treatments +import django.core.validators +from django.db import migrations, models +import django.db.models.deletion +import ishtar_common.models_common +import re + + +class Migration(migrations.Migration): + + dependencies = [ + ('archaeological_finds', '0139_data_migration_owner_ownership'), + ] + operations = [ + migrations.AlterField( + model_name='find', + name='preservation_to_considers', + field=models.ManyToManyField(blank=True, related_name='finds_old_recommended', to='archaeological_finds.TreatmentType', verbose_name='Recommended treatments'), + ), + migrations.CreateModel( + name='RecommendedTreatmentType', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('label', models.TextField(verbose_name='Label')), + ('txt_idx', models.TextField(help_text='The slug is the standardized version of the name. It contains only lowercase letters, numbers and hyphens. Each slug must be unique.', unique=True, validators=[django.core.validators.RegexValidator(re.compile('^[-a-zA-Z0-9_]+\\Z'), "Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens.", 'invalid')], verbose_name='Textual ID')), + ('comment', models.TextField(blank=True, default='', verbose_name='Comment')), + ('available', models.BooleanField(default=True, verbose_name='Available')), + ('order', models.IntegerField(default=10, verbose_name='Order')), + ('parent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='archaeological_finds.RecommendedTreatmentType', verbose_name='Parent')), + ], + options={ + 'verbose_name': 'Recommended treatment type', + 'verbose_name_plural': 'Recommended treatment types', + 'ordering': ('parent__order', 'parent__label', 'order', 'label'), + }, + bases=(ishtar_common.models_common.Cached, models.Model), + ), + migrations.AddField( + model_name='find', + name='recommended_treatments', + field=models.ManyToManyField(blank=True, related_name='finds_recommended', to='archaeological_finds.RecommendedTreatmentType', verbose_name='Recommended treatments'), + ), + ] diff --git a/archaeological_finds/migrations/0141_data_migration_recommanded_treatments.json b/archaeological_finds/migrations/0141_data_migration_recommanded_treatments.json new file mode 100644 index 000000000..6739f836f --- /dev/null +++ b/archaeological_finds/migrations/0141_data_migration_recommanded_treatments.json @@ -0,0 +1,375 @@ +[ +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "Tous mat\u00e9riaux", + "txt_idx": "tous-materiaux", + "comment": "", + "available": true, + "order": 10, + "parent": null + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "Sp\u00e9cifique m\u00e9tal", + "txt_idx": "specifique-metal", + "comment": "", + "available": true, + "order": 20, + "parent": null + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "Dessalement", + "txt_idx": "dessalement", + "comment": "", + "available": true, + "order": 10, + "parent": [ + "tous-materiaux" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "Collage", + "txt_idx": "collage", + "comment": "", + "available": true, + "order": 20, + "parent": [ + "tous-materiaux" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "Comblement", + "txt_idx": "comblement", + "comment": "", + "available": true, + "order": 30, + "parent": [ + "tous-materiaux" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "Consolidation ", + "txt_idx": "consolidation", + "comment": "", + "available": true, + "order": 40, + "parent": [ + "tous-materiaux" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "Remontage", + "txt_idx": "remontage", + "comment": "", + "available": true, + "order": 50, + "parent": [ + "tous-materiaux" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "D\u00e9montage", + "txt_idx": "demontage", + "comment": "", + "available": true, + "order": 60, + "parent": [ + "tous-materiaux" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "D\u00e9restauration", + "txt_idx": "derestauration", + "comment": "", + "available": true, + "order": 70, + "parent": [ + "tous-materiaux" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "\u00c9limination des comblements", + "txt_idx": "limination-des-comblements", + "comment": "", + "available": true, + "order": 80, + "parent": [ + "tous-materiaux" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "\u00c9limination des concr\u00e9tions", + "txt_idx": "limination-des-concretions", + "comment": "", + "available": true, + "order": 90, + "parent": [ + "tous-materiaux" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "\u00c9limination des d\u00e9p\u00f4ts", + "txt_idx": "limination-des-depots", + "comment": "", + "available": true, + "order": 100, + "parent": [ + "tous-materiaux" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "Nettoyage", + "txt_idx": "nettoyage", + "comment": "", + "available": true, + "order": 110, + "parent": [ + "tous-materiaux" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "Reprise des anciens comblements", + "txt_idx": "reprise-des-anciens-comblements", + "comment": "", + "available": true, + "order": 120, + "parent": [ + "tous-materiaux" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "Mise en couleur", + "txt_idx": "mise-en-couleur", + "comment": "", + "available": true, + "order": 130, + "parent": [ + "tous-materiaux" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "R\u00e9int\u00e9gration", + "txt_idx": "reintegration", + "comment": "", + "available": true, + "order": 140, + "parent": [ + "tous-materiaux" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "Marquage", + "txt_idx": "marquage", + "comment": "", + "available": true, + "order": 150, + "parent": [ + "tous-materiaux" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "Analyses", + "txt_idx": "analyses", + "comment": "", + "available": true, + "order": 160, + "parent": [ + "tous-materiaux" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "Radiographie X", + "txt_idx": "radiographie-x", + "comment": "", + "available": true, + "order": 170, + "parent": [ + "tous-materiaux" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "Conditionnement sp\u00e9cifique", + "txt_idx": "conditionnement-specifique", + "comment": "", + "available": true, + "order": 180, + "parent": [ + "tous-materiaux" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "Soclage", + "txt_idx": "soclage", + "comment": "", + "available": true, + "order": 190, + "parent": [ + "tous-materiaux" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "D\u00e9chloruration", + "txt_idx": "dechloruration", + "comment": "", + "available": true, + "order": 10, + "parent": [ + "specifique-metal" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "\u00c9limination des anciens rev\u00eatements", + "txt_idx": "limination-des-anciens-revetements", + "comment": "", + "available": true, + "order": 20, + "parent": [ + "specifique-metal" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "\u00c9limination des produits de corrosion", + "txt_idx": "limination-des-produits-de-corrosion", + "comment": "", + "available": true, + "order": 30, + "parent": [ + "specifique-metal" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "Inhibition", + "txt_idx": "inhibition", + "comment": "", + "available": true, + "order": 40, + "parent": [ + "specifique-metal" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "Passivation", + "txt_idx": "passivation", + "comment": "", + "available": true, + "order": 50, + "parent": [ + "specifique-metal" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "Protection de surface", + "txt_idx": "protection-de-surface", + "comment": "", + "available": true, + "order": 60, + "parent": [ + "specifique-metal" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "Restitution de la lisibilit\u00e9 de surface", + "txt_idx": "restitution-de-la-lisibilite-de-surface", + "comment": "", + "available": true, + "order": 70, + "parent": [ + "specifique-metal" + ] + } +}, +{ + "model": "archaeological_finds.recommendedtreatmenttype", + "fields": { + "label": "Stabilisation", + "txt_idx": "stabilisation", + "comment": "", + "available": true, + "order": 80, + "parent": [ + "specifique-metal" + ] + } +} +] diff --git a/archaeological_finds/migrations/0141_data_migration_recommanded_treatments.py b/archaeological_finds/migrations/0141_data_migration_recommanded_treatments.py new file mode 100644 index 000000000..034c34a4c --- /dev/null +++ b/archaeological_finds/migrations/0141_data_migration_recommanded_treatments.py @@ -0,0 +1,44 @@ +import os + +from django.db import migrations +from django.core.management import call_command + + +def load_data(apps, __): + migration = "0141_data_migration_recommanded_treatments.json" + json_path = os.sep.join(os.path.abspath(__file__).split(os.sep)[:-1] + [migration]) + call_command("loaddata", json_path) + Find = apps.get_model("archaeological_finds", "find") + if not hasattr(Find, "preservation_to_considers"): + return + q = Find.objects.filter(preservation_to_considers__isnull=False) + if not q.count(): + return + TreatmentType = apps.get_model("archaeological_finds", "TreatmentType") + RecommendedTreatmentType = apps.get_model("archaeological_finds", "RecommendedTreatmentType") + parent = RecommendedTreatmentType.objects.create( + label="Anciennes recommandations", + txt_idx="anciennes-recommandations", + order=999, + ) + reco = {} + for find in q.all(): + for treatment_type in find.preservation_to_considers.all(): + if treatment_type.txt_idx not in reco: + reco[treatment_type.txt_idx] = RecommendedTreatmentType.objects.create( + label=treatment_type.label, + txt_idx=treatment_type.txt_idx, + parent=parent + ) + find.recommended_treatments.add(reco[treatment_type.txt_idx]) + + +class Migration(migrations.Migration): + + dependencies = [ + ('archaeological_finds', '0140_recommanded_treatments'), + ] + + operations = [ + migrations.RunPython(load_data) + ] |