summaryrefslogtreecommitdiff
path: root/archaeological_finds/migrations
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2024-02-29 15:06:43 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2024-04-16 16:43:02 +0200
commit1bb16f58b96cdb1a95611178c42401592cdb3b82 (patch)
tree736c15cdc6f28c2364c592a793e5feb9f13a96eb /archaeological_finds/migrations
parent35cdf463830050813ea4e8835eb032ae471c3fda (diff)
downloadIshtar-1bb16f58b96cdb1a95611178c42401592cdb3b82.tar.bz2
Ishtar-1bb16f58b96cdb1a95611178c42401592cdb3b82.zip
🔧 fix default settings for treatment states and treatments types (#5782, #5774)
Diffstat (limited to 'archaeological_finds/migrations')
-rw-r--r--archaeological_finds/migrations/0121_fix_bad_treatment_types_states.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/archaeological_finds/migrations/0121_fix_bad_treatment_types_states.py b/archaeological_finds/migrations/0121_fix_bad_treatment_types_states.py
new file mode 100644
index 000000000..0f5db59f5
--- /dev/null
+++ b/archaeological_finds/migrations/0121_fix_bad_treatment_types_states.py
@@ -0,0 +1,56 @@
+# Generated by Django 2.2.24 on 2024-02-29 12:08
+
+from django.db import migrations
+
+
+def fix_typo(apps, __):
+ TreatmentState = apps.get_model("archaeological_finds", "treatmentstate")
+ q = TreatmentState.objects.filter(txt_idx='completed')
+ if q.count():
+ completed = q.all()[0]
+ completed.executed = True
+ completed.save()
+ else:
+ TreatmentState.objects.create(txt_idx='completed', available=True, label="Achevé")
+ for t in TreatmentState.objects.all():
+ if "_" in t.txt_idx:
+ t.txt_idx = t.txt_idx.replace("_", "-")
+ t.save()
+ TreatmentType = apps.get_model("archaeological_finds", "treatmenttype")
+ tt = [
+ # (slug, condition, fix)
+ ("packaging", {"change_current_location": False},
+ {"change_current_location": True, "change_reference_location": True}),
+ ("moving", {"change_current_location": False},
+ {"change_current_location": True, "change_reference_location": True}),
+ ("physical_grouping", {"create_new_find": False}, {"create_new_find": True}),
+ ("split", {"create_new_find": False}, {"create_new_find": True}),
+ ("reassembly", {"create_new_find": False}, {"create_new_find": True}),
+ ("loan", {"change_current_location": False}, {"change_current_location": True}),
+ ("loan-return", {"restore_reference_location": False}, {"restore_reference_location": True}),
+ ]
+ for slug, condition, fix in tt:
+ q = TreatmentType.objects.filter(txt_idx=slug).filter(**condition)
+ if not q.count():
+ continue
+ t = q.all()[0]
+ for attr, value in fix.items():
+ setattr(t, attr, value)
+ t.save()
+ for t in TreatmentType.objects.all():
+ if t.txt_idx == "radioX":
+ t.txt_idx = "x-ray"
+ t.save()
+ if "_" in t.txt_idx:
+ t.txt_idx = t.txt_idx.replace("_", "-")
+ t.save()
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ('archaeological_finds', '0120_museum_assigned_institution'),
+ ]
+
+ operations = [
+ migrations.RunPython(fix_typo)
+ ]