diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2024-03-08 11:02:06 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2024-04-16 16:43:02 +0200 |
commit | 16ef679607a95d4e78f3fcbe5e7528e935ef5c8c (patch) | |
tree | 3f7ca2453ef5787fd71111f61179a5fcc4bf41d8 /ishtar_common/migrations | |
parent | c9731c233ae84841b61a9751cc6140290d101770 (diff) | |
download | Ishtar-16ef679607a95d4e78f3fcbe5e7528e935ef5c8c.tar.bz2 Ishtar-16ef679607a95d4e78f3fcbe5e7528e935ef5c8c.zip |
🏷️ update french states and departments
Diffstat (limited to 'ishtar_common/migrations')
-rw-r--r-- | ishtar_common/migrations/0240_state_number_max_len.py | 36 | ||||
-rw-r--r-- | ishtar_common/migrations/0241_migrate_old_department.py | 50 |
2 files changed, 86 insertions, 0 deletions
diff --git a/ishtar_common/migrations/0240_state_number_max_len.py b/ishtar_common/migrations/0240_state_number_max_len.py new file mode 100644 index 000000000..3755035cf --- /dev/null +++ b/ishtar_common/migrations/0240_state_number_max_len.py @@ -0,0 +1,36 @@ +# Generated by Django 2.2.24 on 2024-03-08 10:15 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0239_shootingangle_parent'), + ] + + operations = [ + migrations.AlterModelOptions( + name='language', + options={'verbose_name': 'Language type', 'verbose_name_plural': 'Language types'}, + ), + migrations.AlterModelOptions( + name='shootingangle', + options={'ordering': ('order', 'label'), 'verbose_name': 'Shooting angle type', 'verbose_name_plural': 'Shooting angle types'}, + ), + migrations.AlterField( + model_name='historicalorganization', + name='museum_museofile_id', + field=models.TextField(blank=True, default='', verbose_name='Museofile ID'), + ), + migrations.AlterField( + model_name='organization', + name='museum_museofile_id', + field=models.TextField(blank=True, default='', verbose_name='Museofile ID'), + ), + migrations.AlterField( + model_name='state', + name='number', + field=models.CharField(max_length=10, unique=True, verbose_name='Number'), + ), + ] diff --git a/ishtar_common/migrations/0241_migrate_old_department.py b/ishtar_common/migrations/0241_migrate_old_department.py new file mode 100644 index 000000000..4e5c2432a --- /dev/null +++ b/ishtar_common/migrations/0241_migrate_old_department.py @@ -0,0 +1,50 @@ +# Generated by Django 2.2.24 on 2024-03-07 17:52 + +from django.db import migrations +from django.db.models.functions import Length +from ishtar_common.data import FRENCH_STATES, FRENCH_TOM_STATES + + +def migrate(apps, __): + Area = apps.get_model('ishtar_common', 'Area') + Department = apps.get_model('ishtar_common', 'Department') + State = apps.get_model('ishtar_common', 'State') + Town = apps.get_model('ishtar_common', 'Town') + + if not State.objects.filter(label="Nord-Pas-de-Calais").count(): + # already OK or not french + return + + State.objects.filter(pk__isnull=False).delete() + Area.objects.filter(txt_idx__startswith="dep-").delete() + Area.objects.filter(txt_idx__startswith="state-").delete() + + for lbl, code, departments in (FRENCH_STATES + FRENCH_TOM_STATES): + state = State.objects.create(label=lbl, number=code) + state_area = Area.objects.create(label=lbl, txt_idx=f'state-{code}') + for dep_code in departments: + q = Department.objects.filter(number=dep_code) + if not q.count(): + print(f"{dep_code} department is missing") + continue + dep = q.all()[0] + dep.state = state + dep.save() + dep_area = Area.objects.create(label=dep.label, txt_idx=f'dep-{dep.number}') + dep_area.parent = state_area + dep_area.save() + dep_area.towns.clear() + q2 = Town.objects.annotate(insee_len=Length('numero_insee')).filter( + numero_insee__startswith=dep_code, insee_len=5) + dep_area.towns.add(*list(q2.all())) + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0240_state_number_max_len'), + ] + + operations = [ + migrations.RunPython(migrate) + ] |