diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-09 13:09:00 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-13 18:26:04 +0200 |
commit | a9597946a8c9a1a7de2c590ef0b87d2949994920 (patch) | |
tree | 65cfe7698eb328526dca64e7f36a66aa8b545f73 /archaeological_operations/migrations | |
parent | fccd2510276e510132d121cd88e76d62b1899122 (diff) | |
download | Ishtar-a9597946a8c9a1a7de2c590ef0b87d2949994920.tar.bz2 Ishtar-a9597946a8c9a1a7de2c590ef0b87d2949994920.zip |
Record quality: migrate to a type
Diffstat (limited to 'archaeological_operations/migrations')
3 files changed, 131 insertions, 0 deletions
diff --git a/archaeological_operations/migrations/0034_archaeologicalsite_cached_label.py b/archaeological_operations/migrations/0034_archaeologicalsite_cached_label.py new file mode 100644 index 000000000..c4bd2e765 --- /dev/null +++ b/archaeological_operations/migrations/0034_archaeologicalsite_cached_label.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2018-08-08 18:58 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('archaeological_operations', '0033_parcel_cached_label'), + ] + + operations = [ + migrations.AddField( + model_name='archaeologicalsite', + name='cached_label', + field=models.TextField(blank=True, db_index=True, null=True, verbose_name='Cached name'), + ), + ] diff --git a/archaeological_operations/migrations/0035_auto_20180809_1152.py b/archaeological_operations/migrations/0035_auto_20180809_1152.py new file mode 100644 index 000000000..cb88d6119 --- /dev/null +++ b/archaeological_operations/migrations/0035_auto_20180809_1152.py @@ -0,0 +1,88 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2018-08-09 11:52 +from __future__ import unicode_literals + +import django.core.validators +from django.db import migrations, models +import django.db.models.deletion +import ishtar_common.models +import re + + +def migrate_operation(apps, schema_editor): + Operation = apps.get_model('archaeological_operations', 'Operation') + RecordQualityType = apps.get_model('archaeological_operations', + 'RecordQualityType') + + not_documented, c = RecordQualityType.objects.get_or_create( + txt_idx=u"not-documented", + defaults={ + "label": u"Non documenté", + "order": 10 + } + ) + arbitrary, c = RecordQualityType.objects.get_or_create( + txt_idx=u"arbitrary", + defaults={ + "label": u"Arbitraire", + "order": 20 + } + ) + reliable, c = RecordQualityType.objects.get_or_create( + txt_idx=u"reliable", + defaults={ + "label": u"Fiable", + "order": 30 + } + ) + QUALITY = { + 'ND': not_documented, + 'A': arbitrary, + 'R': reliable + } + for operation in Operation.objects.all(): + if not operation.record_quality: + continue + if operation.record_quality not in QUALITY: + continue + operation.record_quality_type = QUALITY[operation.record_quality] + operation.skip_history_when_saving = True + operation.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('archaeological_operations', '0034_archaeologicalsite_cached_label'), + ] + + operations = [ + migrations.CreateModel( + name='RecordQualityType', + 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, null=True, verbose_name='Comment')), + ('available', models.BooleanField(default=True, verbose_name='Available')), + ('order', models.IntegerField(verbose_name='Order')), + ], + options={ + 'ordering': ('order',), + 'verbose_name': 'Type of record quality', + 'verbose_name_plural': 'Types of record quality', + }, + bases=(ishtar_common.models.Cached, models.Model), + ), + migrations.AddField( + model_name='historicaloperation', + name='record_quality_type', + field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='archaeological_operations.RecordQualityType'), + ), + migrations.AddField( + model_name='operation', + name='record_quality_type', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='archaeological_operations.RecordQualityType', verbose_name='Record quality'), + ), + migrations.RunPython(migrate_operation), + ] diff --git a/archaeological_operations/migrations/0036_auto_20180809_1242.py b/archaeological_operations/migrations/0036_auto_20180809_1242.py new file mode 100644 index 000000000..9e8d89fa2 --- /dev/null +++ b/archaeological_operations/migrations/0036_auto_20180809_1242.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2018-08-09 12:42 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('archaeological_operations', '0035_auto_20180809_1152'), + ] + + operations = [ + migrations.RemoveField( + model_name='historicaloperation', + name='record_quality', + ), + migrations.RemoveField( + model_name='operation', + name='record_quality', + ), + ] |