diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-05-30 20:26:21 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-06-12 09:57:24 +0200 |
commit | 66a376e081e335cf94ecf6fd41e5fe13a5445c57 (patch) | |
tree | 981ddce21bc6bad956c5b012baf9608fdfe909b1 /archaeological_finds | |
parent | 3f3c588de0995c1aec212772059f921c165abfac (diff) | |
download | Ishtar-66a376e081e335cf94ecf6fd41e5fe13a5445c57.tar.bz2 Ishtar-66a376e081e335cf94ecf6fd41e5fe13a5445c57.zip |
Migrate images and sources to new document model (refs #4107)
Diffstat (limited to 'archaeological_finds')
-rw-r--r-- | archaeological_finds/migrations/0027_auto_20180530_1900.py | 167 | ||||
-rw-r--r-- | archaeological_finds/migrations/0028_migrate_source_and_image.py | 44 | ||||
-rw-r--r-- | archaeological_finds/models_finds.py | 15 | ||||
-rw-r--r-- | archaeological_finds/models_treatments.py | 34 |
4 files changed, 240 insertions, 20 deletions
diff --git a/archaeological_finds/migrations/0027_auto_20180530_1900.py b/archaeological_finds/migrations/0027_auto_20180530_1900.py new file mode 100644 index 000000000..0a8181056 --- /dev/null +++ b/archaeological_finds/migrations/0027_auto_20180530_1900.py @@ -0,0 +1,167 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2018-05-30 19:00 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0055_auto_20180530_1900'), + ('archaeological_finds', '0026_auto_20180511_1233'), + ] + + operations = [ + migrations.AddField( + model_name='find', + name='documents', + field=models.ManyToManyField(blank=True, related_name='finds', to='ishtar_common.Document', verbose_name='Documents'), + ), + migrations.AddField( + model_name='findsource', + name='associated_links', + field=models.TextField(blank=True, null=True, verbose_name='Symbolic links'), + ), + migrations.AddField( + model_name='findsource', + name='authors_raw', + field=models.CharField(blank=True, max_length=250, null=True, verbose_name='Authors (raw)'), + ), + migrations.AddField( + model_name='findsource', + name='index', + field=models.IntegerField(blank=True, null=True, verbose_name='Index'), + ), + migrations.AddField( + model_name='findsource', + name='licenses', + field=models.ManyToManyField(blank=True, to='ishtar_common.LicenseType', verbose_name='License'), + ), + migrations.AddField( + model_name='treatment', + name='documents', + field=models.ManyToManyField(blank=True, related_name='treatments', to='ishtar_common.Document', verbose_name='Documents'), + ), + migrations.AddField( + model_name='treatmentfile', + name='documents', + field=models.ManyToManyField(blank=True, related_name='treatment_files', to='ishtar_common.Document', verbose_name='Documents'), + ), + migrations.AddField( + model_name='treatmentfilesource', + name='associated_links', + field=models.TextField(blank=True, null=True, verbose_name='Symbolic links'), + ), + migrations.AddField( + model_name='treatmentfilesource', + name='authors_raw', + field=models.CharField(blank=True, max_length=250, null=True, verbose_name='Authors (raw)'), + ), + migrations.AddField( + model_name='treatmentfilesource', + name='index', + field=models.IntegerField(blank=True, null=True, verbose_name='Index'), + ), + migrations.AddField( + model_name='treatmentfilesource', + name='licenses', + field=models.ManyToManyField(blank=True, to='ishtar_common.LicenseType', verbose_name='License'), + ), + migrations.AddField( + model_name='treatmentsource', + name='associated_links', + field=models.TextField(blank=True, null=True, verbose_name='Symbolic links'), + ), + migrations.AddField( + model_name='treatmentsource', + name='authors_raw', + field=models.CharField(blank=True, max_length=250, null=True, verbose_name='Authors (raw)'), + ), + migrations.AddField( + model_name='treatmentsource', + name='index', + field=models.IntegerField(blank=True, null=True, verbose_name='Index'), + ), + migrations.AddField( + model_name='treatmentsource', + name='licenses', + field=models.ManyToManyField(blank=True, to='ishtar_common.LicenseType', verbose_name='License'), + ), + migrations.AlterField( + model_name='findsource', + name='external_id', + field=models.TextField(blank=True, null=True, verbose_name='External ID'), + ), + migrations.AlterField( + model_name='findsource', + name='internal_reference', + field=models.TextField(blank=True, null=True, verbose_name='Internal ref.'), + ), + migrations.AlterField( + model_name='findsource', + name='reference', + field=models.TextField(blank=True, null=True, verbose_name='Ref.'), + ), + migrations.AlterField( + model_name='findsource', + name='source_type', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='ishtar_common.SourceType', verbose_name='Type'), + ), + migrations.AlterField( + model_name='findsource', + name='title', + field=models.TextField(blank=True, default=b'', verbose_name='Title'), + ), + migrations.AlterField( + model_name='treatmentfilesource', + name='external_id', + field=models.TextField(blank=True, null=True, verbose_name='External ID'), + ), + migrations.AlterField( + model_name='treatmentfilesource', + name='internal_reference', + field=models.TextField(blank=True, null=True, verbose_name='Internal ref.'), + ), + migrations.AlterField( + model_name='treatmentfilesource', + name='reference', + field=models.TextField(blank=True, null=True, verbose_name='Ref.'), + ), + migrations.AlterField( + model_name='treatmentfilesource', + name='source_type', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='ishtar_common.SourceType', verbose_name='Type'), + ), + migrations.AlterField( + model_name='treatmentfilesource', + name='title', + field=models.TextField(blank=True, default=b'', verbose_name='Title'), + ), + migrations.AlterField( + model_name='treatmentsource', + name='external_id', + field=models.TextField(blank=True, null=True, verbose_name='External ID'), + ), + migrations.AlterField( + model_name='treatmentsource', + name='internal_reference', + field=models.TextField(blank=True, null=True, verbose_name='Internal ref.'), + ), + migrations.AlterField( + model_name='treatmentsource', + name='reference', + field=models.TextField(blank=True, null=True, verbose_name='Ref.'), + ), + migrations.AlterField( + model_name='treatmentsource', + name='source_type', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='ishtar_common.SourceType', verbose_name='Type'), + ), + migrations.AlterField( + model_name='treatmentsource', + name='title', + field=models.TextField(blank=True, default=b'', verbose_name='Title'), + ), + ] diff --git a/archaeological_finds/migrations/0028_migrate_source_and_image.py b/archaeological_finds/migrations/0028_migrate_source_and_image.py new file mode 100644 index 000000000..8f95de8ba --- /dev/null +++ b/archaeological_finds/migrations/0028_migrate_source_and_image.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2018-05-30 19:40 +from __future__ import unicode_literals + +from django.db import migrations + +from ishtar_common.utils_migrations import migrate_images, migrate_sources + + +def migrate_source_and_image(apps, schema_editor): + Find = apps.get_model( + 'archaeological_finds', 'Find') + FindImage = apps.get_model( + 'archaeological_finds', 'FindImage') + FindSource = apps.get_model( + 'archaeological_finds', 'FindSource') + migrate_images(apps, Find, FindImage) + migrate_sources(apps, Find, FindSource, 'find') + + Treatment = apps.get_model( + 'archaeological_finds', 'Treatment') + TreatmentImage = apps.get_model( + 'archaeological_finds', 'TreatmentImage') + TreatmentSource = apps.get_model( + 'archaeological_finds', 'TreatmentSource') + migrate_images(apps, Treatment, TreatmentImage) + migrate_sources(apps, Treatment, TreatmentSource, 'treatment') + + TreatmentFile = apps.get_model( + 'archaeological_finds', 'TreatmentFile') + TreatmentFileSource = apps.get_model( + 'archaeological_finds', 'TreatmentFileSource') + migrate_sources(apps, TreatmentFile, TreatmentFileSource, 'treatment_file') + + +class Migration(migrations.Migration): + + dependencies = [ + ('archaeological_finds', '0027_auto_20180530_1900'), + ] + + operations = [ + migrations.RunPython(migrate_source_and_image) + ] diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index dadda2003..0e36cf29a 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -32,9 +32,9 @@ from django.utils.translation import ugettext_lazy as _ from ishtar_common.data_importer import post_importer_action, ImporterError from ishtar_common.utils import cached_label_changed, post_save_point -from ishtar_common.models import GeneralType, HierarchicalType, \ - BaseHistorizedItem, ShortMenuItem, LightHistorizedItem, \ - HistoricalRecords, OwnPerms, Source, Person, Basket, post_save_cache, \ +from ishtar_common.models import BaseSource, Document, GeneralType, \ + HierarchicalType, BaseHistorizedItem, ShortMenuItem, LightHistorizedItem, \ + HistoricalRecords, OwnPerms, Person, Basket, post_save_cache, \ ValueGetter, get_current_profile, IshtarImage, ThroughImage from archaeological_operations.models import AdministrativeAct, Operation @@ -828,6 +828,9 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms, null=True) appraisal_date = models.DateField(_(u"Appraisal date"), blank=True, null=True) + documents = models.ManyToManyField( + Document, related_name='finds', verbose_name=_(u"Documents"), + blank=True) images = models.ManyToManyField(IshtarImage, verbose_name=_(u"Images"), blank=True, through='FindImage') cached_label = models.TextField(_(u"Cached name"), null=True, blank=True, @@ -1443,13 +1446,13 @@ class FindImage(ThroughImage): related_name='associated_images') -class FindSource(Source): +class FindSource(BaseSource): SHOW_URL = 'show-findsource' MODIFY_URL = 'find_source_modify' TABLE_COLS = [ 'find__base_finds__context_record__operation', 'find__base_finds__context_record', 'find'] + \ - Source.TABLE_COLS + BaseSource.TABLE_COLS # search parameters BOOL_FIELDS = ['duplicate'] @@ -1475,7 +1478,7 @@ class FindSource(Source): 'find__datings__period': 'find__datings__period__pk', 'find__description': 'find__description__icontains', } - PARENT_SEARCH_VECTORS = Source.PARENT_SEARCH_VECTORS + ['find'] + PARENT_SEARCH_VECTORS = BaseSource.PARENT_SEARCH_VECTORS + ['find'] class Meta: verbose_name = _(u"Find documentation") diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py index 2baced6e1..19f00de1f 100644 --- a/archaeological_finds/models_treatments.py +++ b/archaeological_finds/models_treatments.py @@ -24,17 +24,16 @@ from django.contrib.gis.db import models from django.db.models import Max, Q from django.db.models.signals import post_save, post_delete, pre_delete from django.template.defaultfilters import slugify -from django.utils.translation import ugettext_lazy as _, ugettext +from django.utils.translation import ugettext_lazy as _ - -from ishtar_common.utils import cached_label_changed, get_current_year -from ishtar_common.models import GeneralType, ImageModel, BaseHistorizedItem, \ - OwnPerms, HistoricalRecords, Person, Organization, Source, \ - ValueGetter, post_save_cache, ShortMenuItem, DashboardFormItem, \ - IshtarImage, ThroughImage -from archaeological_warehouse.models import Warehouse, Container from archaeological_finds.models_finds import Find, FindBasket, TreatmentType from archaeological_operations.models import ClosedItem, Operation +from archaeological_warehouse.models import Warehouse, Container +from ishtar_common.models import BaseSource, Document, GeneralType, \ + ImageModel, BaseHistorizedItem, OwnPerms, HistoricalRecords, Person, \ + Organization, ValueGetter, post_save_cache, ShortMenuItem, \ + DashboardFormItem, IshtarImage, ThroughImage +from ishtar_common.utils import cached_label_changed, get_current_year class TreatmentState(GeneralType): @@ -125,6 +124,9 @@ class Treatment(DashboardFormItem, ValueGetter, BaseHistorizedItem, blank=True, null=True) target_is_basket = models.BooleanField(_(u"Target a basket"), default=False) + documents = models.ManyToManyField( + Document, related_name='treatments', verbose_name=_(u"Documents"), + blank=True) images = models.ManyToManyField(IshtarImage, verbose_name=_(u"Images"), blank=True, through='TreatmentImage') cached_label = models.TextField(_(u"Cached name"), null=True, blank=True, @@ -533,6 +535,9 @@ class TreatmentFile(DashboardFormItem, ClosedItem, BaseHistorizedItem, reception_date = models.DateField(_(u'Reception date'), blank=True, null=True) comment = models.TextField(_(u"Comment"), null=True, blank=True) + documents = models.ManyToManyField( + Document, related_name='treatment_files', verbose_name=_(u"Documents"), + blank=True) cached_label = models.TextField(_(u"Cached name"), null=True, blank=True, db_index=True) history = HistoricalRecords() @@ -611,14 +616,14 @@ class TreatmentFile(DashboardFormItem, ClosedItem, BaseHistorizedItem, post_save.connect(cached_label_changed, sender=TreatmentFile) -class TreatmentSource(Source): +class TreatmentSource(BaseSource): treatment = models.ForeignKey( Treatment, verbose_name=_(u"Treatment"), related_name="source") BOOL_FIELDS = ['duplicate'] - TABLE_COLS = ['treatment__cached_label'] + Source.TABLE_COLS + TABLE_COLS = ['treatment__cached_label'] + BaseSource.TABLE_COLS COL_LABELS = {'treatment__cached_label': _(u"Treatment")} SHOW_URL = 'show-treatmentsource' - PARENT_SEARCH_VECTORS = Source.PARENT_SEARCH_VECTORS + ['treatment'] + PARENT_SEARCH_VECTORS = BaseSource.PARENT_SEARCH_VECTORS + ['treatment'] class Meta: verbose_name = _(u"Treatment documentation") @@ -644,15 +649,16 @@ class TreatmentSource(Source): return u"{}/source".format(self.treatment._get_base_image_path()) -class TreatmentFileSource(Source): +class TreatmentFileSource(BaseSource): treatment_file = models.ForeignKey( TreatmentFile, verbose_name=_(u"Treatment request"), related_name="source") BOOL_FIELDS = ['duplicate'] - TABLE_COLS = ['treatment_file__cached_label'] + Source.TABLE_COLS + TABLE_COLS = ['treatment_file__cached_label'] + BaseSource.TABLE_COLS COL_LABELS = {'treatment_file__cached_label': _(u"Treatment file")} SHOW_URL = 'show-treatmentfilesource' - PARENT_SEARCH_VECTORS = Source.PARENT_SEARCH_VECTORS + ['treatment_file'] + PARENT_SEARCH_VECTORS = BaseSource.PARENT_SEARCH_VECTORS + [ + 'treatment_file'] class Meta: verbose_name = _(u"Treatment request documentation") |