diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-10-06 19:44:11 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-28 12:15:21 +0100 |
commit | ce17a92be9c98753911987d12bf30ea9485e8e3f (patch) | |
tree | 04961ac0119f44f5c46cb4356733f8bf2b5b0c1d | |
parent | c37576c628db687260975c0d1d219c196a2bc9a5 (diff) | |
download | Ishtar-ce17a92be9c98753911987d12bf30ea9485e8e3f.tar.bz2 Ishtar-ce17a92be9c98753911987d12bf30ea9485e8e3f.zip |
Complete identifier field: database - profile settings - save
-rw-r--r-- | archaeological_context_records/migrations/0104_auto_20201007_1215.py | 25 | ||||
-rw-r--r-- | archaeological_context_records/models.py | 4 | ||||
-rw-r--r-- | archaeological_files/migrations/0103_auto_20201007_1215.py | 36 | ||||
-rw-r--r-- | archaeological_files/models.py | 10 | ||||
-rw-r--r-- | archaeological_finds/migrations/0106_auto_20201007_1215.py | 46 | ||||
-rw-r--r-- | archaeological_finds/models_finds.py | 8 | ||||
-rw-r--r-- | archaeological_operations/migrations/0104_auto_20201007_1215.py | 39 | ||||
-rw-r--r-- | archaeological_operations/models.py | 10 | ||||
-rw-r--r-- | archaeological_operations/tests.py | 26 | ||||
-rw-r--r-- | archaeological_warehouse/migrations/0105_auto_20201007_1215.py | 30 | ||||
-rw-r--r-- | archaeological_warehouse/models.py | 14 | ||||
-rw-r--r-- | ishtar_common/migrations/0206_auto_20201007_1215.py | 101 | ||||
-rw-r--r-- | ishtar_common/models.py | 59 | ||||
-rw-r--r-- | ishtar_common/models_common.py | 27 | ||||
-rw-r--r-- | ishtar_common/utils.py | 3 |
15 files changed, 399 insertions, 39 deletions
diff --git a/archaeological_context_records/migrations/0104_auto_20201007_1215.py b/archaeological_context_records/migrations/0104_auto_20201007_1215.py new file mode 100644 index 000000000..cb59f180c --- /dev/null +++ b/archaeological_context_records/migrations/0104_auto_20201007_1215.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.27 on 2020-10-07 12:15 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('archaeological_context_records', '0103_historicalcontextrecord_history_change_reason'), + ] + + operations = [ + migrations.AddField( + model_name='contextrecord', + name='complete_identifier', + field=models.TextField(blank=True, verbose_name='Complete identifier'), + ), + migrations.AddField( + model_name='historicalcontextrecord', + name='complete_identifier', + field=models.TextField(blank=True, verbose_name='Complete identifier'), + ), + ] diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index c664c39b6..0a7cd3d88 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -39,7 +39,7 @@ from ishtar_common.models import Document, GeneralType, \ GeneralRelationType, GeneralRecordRelations, post_delete_record_relation,\ post_save_cache, ValueGetter, BulkUpdatedItem, \ RelationItem, Town, get_current_profile, document_attached_changed, \ - HistoryModel, SearchAltName, GeoItem, QRCodeItem, SearchVectorConfig, \ + HistoryModel, SearchAltName, GeoItem, CompleteIdentifierItem, SearchVectorConfig, \ DocumentItem, MainItem, QuickAction from ishtar_common.models_common import HistoricalRecords from archaeological_operations.models import Operation, Period, Parcel, \ @@ -338,7 +338,7 @@ class CRBulkView(object): class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem, - QRCodeItem, GeoItem, OwnPerms, ValueGetter, MainItem, + CompleteIdentifierItem, GeoItem, OwnPerms, ValueGetter, MainItem, RelationItem): SLUG = 'contextrecord' APP = "archaeological-context-records" diff --git a/archaeological_files/migrations/0103_auto_20201007_1215.py b/archaeological_files/migrations/0103_auto_20201007_1215.py new file mode 100644 index 000000000..d6f626fa9 --- /dev/null +++ b/archaeological_files/migrations/0103_auto_20201007_1215.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.27 on 2020-10-07 12:15 +from __future__ import unicode_literals + +from django.db import migrations, models +import ishtar_common.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('archaeological_files', '0102_historicalfile_history_change_reason'), + ] + + operations = [ + migrations.AddField( + model_name='file', + name='complete_identifier', + field=models.TextField(blank=True, verbose_name='Complete identifier'), + ), + migrations.AddField( + model_name='file', + name='qrcode', + field=models.ImageField(blank=True, max_length=255, null=True, upload_to=ishtar_common.models.get_image_path), + ), + migrations.AddField( + model_name='historicalfile', + name='complete_identifier', + field=models.TextField(blank=True, verbose_name='Complete identifier'), + ), + migrations.AddField( + model_name='historicalfile', + name='qrcode', + field=models.TextField(blank=True, max_length=255, null=True), + ), + ] diff --git a/archaeological_files/models.py b/archaeological_files/models.py index 8afd57d01..455d65af8 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -34,8 +34,8 @@ from ishtar_common.utils import cached_label_changed, get_cache, \ from ishtar_common.models import GeneralType, BaseHistorizedItem, \ OwnPerms, Person, Organization, Town, \ Dashboard, DashboardFormItem, ValueGetter, ShortMenuItem, \ - OperationType, get_external_id, post_save_cache, Document, HistoryModel, \ - SearchAltName, SearchVectorConfig, DocumentItem + OperationType, get_generated_id, post_save_cache, Document, HistoryModel, \ + SearchAltName, SearchVectorConfig, DocumentItem, CompleteIdentifierItem from ishtar_common.models_common import HistoricalRecords, Department @@ -86,8 +86,8 @@ if settings.COUNTRY == 'fr': post_delete.connect(post_save_cache, sender=SaisineType) -class File(ClosedItem, DocumentItem, BaseHistorizedItem, OwnPerms, ValueGetter, - ShortMenuItem, DashboardFormItem, ParcelItem): +class File(ClosedItem, DocumentItem, BaseHistorizedItem, CompleteIdentifierItem, + OwnPerms, ValueGetter, ShortMenuItem, DashboardFormItem, ParcelItem): SLUG = 'file' SHOW_URL = 'show-file' DELETE_URL = 'delete-file' @@ -716,7 +716,7 @@ class File(ClosedItem, DocumentItem, BaseHistorizedItem, OwnPerms, ValueGetter, updated += self.update_corpo_general_contractor() if not self.external_id or self.auto_external_id: - external_id = get_external_id('file_external_id', self) + external_id = get_generated_id('file_external_id', self) if external_id != self.external_id: updated = True self.auto_external_id = True diff --git a/archaeological_finds/migrations/0106_auto_20201007_1215.py b/archaeological_finds/migrations/0106_auto_20201007_1215.py new file mode 100644 index 000000000..842173d1e --- /dev/null +++ b/archaeological_finds/migrations/0106_auto_20201007_1215.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.27 on 2020-10-07 12:15 +from __future__ import unicode_literals + +from django.db import migrations, models +import ishtar_common.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('archaeological_finds', '0105_auto_20200407_1414'), + ] + + operations = [ + migrations.AddField( + model_name='basefind', + name='complete_identifier', + field=models.TextField(blank=True, verbose_name='Complete identifier'), + ), + migrations.AddField( + model_name='basefind', + name='qrcode', + field=models.ImageField(blank=True, max_length=255, null=True, upload_to=ishtar_common.models.get_image_path), + ), + migrations.AddField( + model_name='find', + name='complete_identifier', + field=models.TextField(blank=True, verbose_name='Complete identifier'), + ), + migrations.AddField( + model_name='historicalbasefind', + name='complete_identifier', + field=models.TextField(blank=True, verbose_name='Complete identifier'), + ), + migrations.AddField( + model_name='historicalbasefind', + name='qrcode', + field=models.TextField(blank=True, max_length=255, null=True), + ), + migrations.AddField( + model_name='historicalfind', + name='complete_identifier', + field=models.TextField(blank=True, verbose_name='Complete identifier'), + ), + ] diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 77fe44da5..b6dfeabfd 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -45,7 +45,7 @@ from ishtar_common.models import Document, GeneralType, \ ValueGetter, get_current_profile, IshtarSiteProfile, \ GeoItem, BulkUpdatedItem, QuickAction, \ MainItem, document_attached_changed, HistoryModel, DynamicRequest, \ - SearchAltName, QRCodeItem, SearchVectorConfig, DocumentItem + SearchAltName, CompleteIdentifierItem, SearchVectorConfig, DocumentItem from ishtar_common.models_common import HistoricalRecords from ishtar_common.utils import PRIVATE_FIELDS @@ -271,8 +271,8 @@ class BFBulkView(object): """ -class BaseFind(BulkUpdatedItem, BaseHistorizedItem, GeoItem, OwnPerms, - ValueGetter): +class BaseFind(BulkUpdatedItem, BaseHistorizedItem, GeoItem, + CompleteIdentifierItem, OwnPerms, ValueGetter): EXTERNAL_ID_KEY = 'base_find_external_id' EXTERNAL_ID_DEPENDENCIES = ['find'] SLUG = 'basefind' @@ -774,7 +774,7 @@ def query_loan(is_true=True): class Find(BulkUpdatedItem, ValueGetter, DocumentItem, BaseHistorizedItem, - QRCodeItem, OwnPerms, MainItem): + CompleteIdentifierItem, OwnPerms, MainItem): SLUG = 'find' APP = "archaeological-finds" MODEL = "find" diff --git a/archaeological_operations/migrations/0104_auto_20201007_1215.py b/archaeological_operations/migrations/0104_auto_20201007_1215.py new file mode 100644 index 000000000..fa61cf836 --- /dev/null +++ b/archaeological_operations/migrations/0104_auto_20201007_1215.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.27 on 2020-10-07 12:15 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('archaeological_operations', '0103_auto_20200129_1941'), + ] + + operations = [ + migrations.AlterModelOptions( + name='recordrelations', + options={'ordering': ('left_record__cached_label', 'relation_type', 'right_record__cached_label'), 'permissions': [('view_operationrelation', 'Can view all Operation relations')], 'verbose_name': 'Operation record relation', 'verbose_name_plural': 'Operation record relations'}, + ), + migrations.AddField( + model_name='archaeologicalsite', + name='complete_identifier', + field=models.TextField(blank=True, verbose_name='Complete identifier'), + ), + migrations.AddField( + model_name='historicalarchaeologicalsite', + name='complete_identifier', + field=models.TextField(blank=True, verbose_name='Complete identifier'), + ), + migrations.AddField( + model_name='historicaloperation', + name='complete_identifier', + field=models.TextField(blank=True, verbose_name='Complete identifier'), + ), + migrations.AddField( + model_name='operation', + name='complete_identifier', + field=models.TextField(blank=True, verbose_name='Complete identifier'), + ), + ] diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index e7561d32c..c690e5b3a 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -42,7 +42,7 @@ from ishtar_common.models import BaseHistorizedItem, Dashboard, \ post_delete_record_relation, post_save_cache, RelationItem, \ ShortMenuItem, SourceType, Town, ValueGetter, get_current_profile, \ document_attached_changed, HistoryModel, SearchAltName, \ - GeoItem, QRCodeItem, SearchVectorConfig, DocumentItem, QuickAction, \ + GeoItem, CompleteIdentifierItem, SearchVectorConfig, DocumentItem, QuickAction, \ MainItem, HierarchicalType from ishtar_common.models_common import Department, HistoricalRecords from ishtar_common.model_managers import UUIDModelManager @@ -122,7 +122,7 @@ post_save.connect(post_save_cache, sender=RecordQualityType) post_delete.connect(post_save_cache, sender=RecordQualityType) -class ArchaeologicalSite(DocumentItem, BaseHistorizedItem, QRCodeItem, +class ArchaeologicalSite(DocumentItem, BaseHistorizedItem, CompleteIdentifierItem, GeoItem, OwnPerms, ValueGetter, MainItem): SLUG = 'site' APP = "archaeological-operations" @@ -697,9 +697,9 @@ class ParcelItem: parcels.append(key) -class Operation(ClosedItem, DocumentItem, BaseHistorizedItem, QRCodeItem, - GeoItem, OwnPerms, ValueGetter, MainItem, - DashboardFormItem, RelationItem, ParcelItem): +class Operation(ClosedItem, DocumentItem, BaseHistorizedItem, + CompleteIdentifierItem, GeoItem, OwnPerms, ValueGetter, + MainItem, DashboardFormItem, RelationItem, ParcelItem): SLUG = 'operation' APP = "archaeological-operations" MODEL = "operation" diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 7b93c7d5e..d2cbb707e 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -1205,7 +1205,9 @@ class OperationInitTest(object): self.create_orgas(user) return self.orgas[0] - def create_towns(self, datas={}): + def create_towns(self, datas=None): + if not datas: + datas = {} default = {'numero_insee': '12345', 'name': 'default_town'} default.update(datas) town = models.Town.objects.create(**default) @@ -1323,6 +1325,28 @@ class OperationTest(TestCase, OperationInitTest): parcel.save() self.assertEqual(parcel.external_id, 'blabla') + def test_complete_identifier(self): + profile = get_current_profile() + profile.operation_complete_identifier = \ + "{code_patriarche}-{town__numero_insee}" + profile.save() + self.item.code_patriarche = '123456789' + self.item.year = 2020 + self.item.save() + self.item = models.Operation.objects.get(pk=self.item.pk) + self.assertEqual(self.item.complete_identifier, + '{}-{}'.format(self.item.code_patriarche, + self.item.town.numero_insee)) + + profile.operation_complete_identifier = \ + "{year}-{town__numero_insee}" + profile.save() + self.item.save() + self.item = models.Operation.objects.get(pk=self.item.pk) + self.assertEqual(self.item.complete_identifier, + '{}-{}'.format(self.item.year, + self.item.town.numero_insee)) + def test_associated(self): scientist = Person.objects.create(name="C-3PO") self.item.scientist = scientist diff --git a/archaeological_warehouse/migrations/0105_auto_20201007_1215.py b/archaeological_warehouse/migrations/0105_auto_20201007_1215.py new file mode 100644 index 000000000..9d009bed1 --- /dev/null +++ b/archaeological_warehouse/migrations/0105_auto_20201007_1215.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.27 on 2020-10-07 12:15 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('archaeological_warehouse', '0104_auto_20200925_1024'), + ] + + operations = [ + migrations.AddField( + model_name='container', + name='complete_identifier', + field=models.TextField(blank=True, verbose_name='Complete identifier'), + ), + migrations.AddField( + model_name='historicalwarehouse', + name='complete_identifier', + field=models.TextField(blank=True, verbose_name='Complete identifier'), + ), + migrations.AddField( + model_name='warehouse', + name='complete_identifier', + field=models.TextField(blank=True, verbose_name='Complete identifier'), + ), + ] diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index 21b6d2b7c..b18a2df5f 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -39,11 +39,11 @@ from ishtar_common.model_managers import ExternalIdManager, UUIDModelManager from ishtar_common.models_common import GeneralType, \ LightHistorizedItem, OwnPerms, Address, post_save_cache, \ DashboardFormItem, document_attached_changed, SearchAltName, \ - DynamicRequest, GeoItem, QRCodeItem, SearchVectorConfig, DocumentItem, \ - QuickAction, MainItem, Merge + DynamicRequest, GeoItem, CompleteIdentifierItem, SearchVectorConfig, \ + DocumentItem, QuickAction, MainItem, Merge from ishtar_common.model_merging import merge_model_objects from ishtar_common.utils import cached_label_changed, \ - cached_label_and_geo_changed, get_external_id + cached_label_and_geo_changed, get_generated_id class DivisionContainer(DashboardFormItem): @@ -254,7 +254,7 @@ post_save.connect(post_save_cache, sender=WarehouseType) post_delete.connect(post_save_cache, sender=WarehouseType) -class Warehouse(Address, DocumentItem, GeoItem, QRCodeItem, +class Warehouse(Address, DocumentItem, GeoItem, CompleteIdentifierItem, OwnPerms, MainItem, DivisionContainer): SLUG = 'warehouse' APP = "archaeological-warehouse" @@ -466,7 +466,7 @@ class Warehouse(Address, DocumentItem, GeoItem, QRCodeItem, self.skip_history_when_saving = True if not self.external_id or self.auto_external_id: - external_id = get_external_id('warehouse_external_id', self) + external_id = get_generated_id('warehouse_external_id', self) if external_id != self.external_id: self.auto_external_id = True self.external_id = external_id @@ -609,7 +609,7 @@ class ContainerTree(models.Model): db_table = 'containers_tree' -class Container(DocumentItem, Merge, LightHistorizedItem, QRCodeItem, GeoItem, +class Container(DocumentItem, Merge, LightHistorizedItem, CompleteIdentifierItem, GeoItem, OwnPerms, MainItem, DivisionContainer): SLUG = 'container' APP = "archaeological-warehouse" @@ -1364,7 +1364,7 @@ class Container(DocumentItem, Merge, LightHistorizedItem, QRCodeItem, GeoItem, self.skip_history_when_saving = True if not self.external_id or self.auto_external_id: - external_id = get_external_id('container_external_id', self) + external_id = get_generated_id('container_external_id', self) if external_id != self.external_id: updated = True self.auto_external_id = True diff --git a/ishtar_common/migrations/0206_auto_20201007_1215.py b/ishtar_common/migrations/0206_auto_20201007_1215.py new file mode 100644 index 000000000..5e6d32c9a --- /dev/null +++ b/ishtar_common/migrations/0206_auto_20201007_1215.py @@ -0,0 +1,101 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.27 on 2020-10-07 12:15 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0205_auto_20200527_1500'), + ] + + operations = [ + migrations.AddField( + model_name='document', + name='complete_identifier', + field=models.TextField(blank=True, verbose_name='Complete identifier'), + ), + migrations.AddField( + model_name='ishtarsiteprofile', + name='basefind_complete_identifier', + field=models.TextField(default='', help_text='Formula to manage base find complete identifier.', verbose_name='Base find complete identifier'), + ), + migrations.AddField( + model_name='ishtarsiteprofile', + name='container_complete_identifier', + field=models.TextField(default='', help_text='Formula to manage container complete identifier.', verbose_name='Container complete identifier'), + ), + migrations.AddField( + model_name='ishtarsiteprofile', + name='context_record_complete_identifier', + field=models.TextField(default='', help_text='Formula to manage context record complete identifier.', verbose_name='Context record complete identifier'), + ), + migrations.AddField( + model_name='ishtarsiteprofile', + name='document_complete_identifier', + field=models.TextField(default='', help_text='Formula to manage document complete identifier.', verbose_name='Document complete identifier'), + ), + migrations.AddField( + model_name='ishtarsiteprofile', + name='file_complete_identifier', + field=models.TextField(default='', help_text='Formula to manage archaeological file complete identifier.', verbose_name='Archaeological file complete identifier'), + ), + migrations.AddField( + model_name='ishtarsiteprofile', + name='find_complete_identifier', + field=models.TextField(default='', help_text='Formula to manage find complete identifier.', verbose_name='Find complete identifier'), + ), + migrations.AddField( + model_name='ishtarsiteprofile', + name='operation_complete_identifier', + field=models.TextField(default='', help_text='Formula to manage operation complete identifier.', verbose_name='Operation complete identifier'), + ), + migrations.AddField( + model_name='ishtarsiteprofile', + name='site_complete_identifier', + field=models.TextField(default='', help_text='Formula to manage archaeological site complete identifier.', verbose_name='Archaeological site complete identifier'), + ), + migrations.AddField( + model_name='ishtarsiteprofile', + name='warehouse_complete_identifier', + field=models.TextField(default='', help_text='Formula to manage warehouse complete identifier.', verbose_name='Warehouse complete identifier'), + ), + migrations.AlterField( + model_name='document', + name='format_type', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='ishtar_common.Format', verbose_name='Medium'), + ), + migrations.AlterField( + model_name='document', + name='publisher', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='publish', to='ishtar_common.Organization', verbose_name='Publisher'), + ), + migrations.AlterField( + model_name='importercolumn', + name='regexp_pre_filter', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='columns', to='ishtar_common.Regexp'), + ), + migrations.AlterField( + model_name='importercolumn', + name='value_format', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='columns', to='ishtar_common.ValueFormater'), + ), + migrations.AlterField( + model_name='importertype', + name='associated_models', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='importer_type_associated', to='ishtar_common.ImporterModel', verbose_name='Associated model'), + ), + migrations.AlterField( + model_name='importertype', + name='created_models', + field=models.ManyToManyField(blank=True, help_text='Leave blank for no restrictions', related_name='importer_type_created', to='ishtar_common.ImporterModel', verbose_name='Models that can accept new items'), + ), + migrations.AlterField( + model_name='importtarget', + name='formater_type', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='targets', to='ishtar_common.FormaterType'), + ), + ] diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 483e15786..07a052470 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -62,7 +62,7 @@ from django.db.utils import DatabaseError from django.template.defaultfilters import slugify from django.utils.functional import lazy from ishtar_common.utils import ugettext_lazy as _, ugettext, \ - pgettext_lazy, get_external_id, get_current_profile, duplicate_item, \ + pgettext_lazy, get_generated_id, get_current_profile, duplicate_item, \ get_image_path from ishtar_common.utils_secretary import IshtarSecretaryRenderer @@ -87,21 +87,22 @@ from ishtar_common.models_common import GeneralType, HierarchicalType, \ FixAssociated, SearchAltName, HistoryError, OwnPerms, Cached, \ Address, post_save_cache, TemplateItem, SpatialReferenceSystem, \ DashboardFormItem, document_attached_changed, SearchAltName, \ - DynamicRequest, GeoItem, QRCodeItem, SearchVectorConfig, DocumentItem, \ - QuickAction, MainItem, Merge, ShortMenuItem, Town, ImageContainerModel, \ - StatisticItem, CachedGen, CascasdeUpdate, Department, State + DynamicRequest, GeoItem, CompleteIdentifierItem, SearchVectorConfig, \ + DocumentItem, QuickAction, MainItem, Merge, ShortMenuItem, Town, \ + ImageContainerModel, StatisticItem, CachedGen, CascasdeUpdate, \ + Department, State __all__ = [ 'ImporterModel', 'ImporterType', 'ImporterDefault', 'ImporterDefaultValues', 'ImporterColumn', 'ImporterDuplicateField', 'Regexp', 'ImportTarget', 'TargetKey', 'FormaterType', 'Import', 'TargetKeyGroup', 'ValueFormater', 'Organization', 'Person', 'valid_id', 'Town', 'SpatialReferenceSystem', - 'OrganizationType', 'Document', 'GeneralType', 'get_external_id', + 'OrganizationType', 'Document', 'GeneralType', 'get_generated_id', 'LightHistorizedItem', 'OwnPerms', 'Address', 'post_save_cache', 'DashboardFormItem', 'ShortMenuItem', 'document_attached_changed', - 'SearchAltName', 'DynamicRequest', 'GeoItem', 'QRCodeItem', + 'SearchAltName', 'DynamicRequest', 'GeoItem', 'SearchVectorConfig', 'DocumentItem', 'CachedGen', 'StatisticItem', - 'CascasdeUpdate', 'Department', 'State' + 'CascasdeUpdate', 'Department', 'State', 'CompleteIdentifierItem' ] logger = logging.getLogger(__name__) @@ -816,6 +817,15 @@ class IshtarSiteProfile(models.Model, Cached): _("Operation region code"), null=True, blank=True, max_length=5 ) + operation_complete_identifier = models.TextField( + _("Operation complete identifier"), + default="", + help_text=_("Formula to manage operation complete identifier.")) + site_complete_identifier = models.TextField( + _("Archaeological site complete identifier"), + default="", + help_text=_("Formula to manage archaeological site complete" + " identifier.")) file_external_id = models.TextField( _("File external id"), default="{year}-{numeric_reference}", @@ -823,6 +833,11 @@ class IshtarSiteProfile(models.Model, Cached): "Change this with care. With incorrect formula, the " "application might be unusable and import of external " "data can be destructive.")) + file_complete_identifier = models.TextField( + _("Archaeological file complete identifier"), + default="", + help_text=_("Formula to manage archaeological file complete " + "identifier.")) parcel_external_id = models.TextField( _("Parcel external id"), default="{associated_file__external_id}{operation__code_patriarche}-" @@ -838,6 +853,10 @@ class IshtarSiteProfile(models.Model, Cached): "Change this with care. With incorrect formula, the " "application might be unusable and import of external " "data can be destructive.")) + context_record_complete_identifier = models.TextField( + _("Context record complete identifier"), + default="", + help_text=_("Formula to manage context record complete identifier.")) base_find_external_id = models.TextField( _("Base find external id"), default="{context_record__external_id}-{label}", @@ -845,6 +864,10 @@ class IshtarSiteProfile(models.Model, Cached): "Change this with care. With incorrect formula, the " "application might be unusable and import of external " "data can be destructive.")) + basefind_complete_identifier = models.TextField( + _("Base find complete identifier"), + default="", + help_text=_("Formula to manage base find complete identifier.")) find_external_id = models.TextField( _("Find external id"), default="{get_first_base_find__context_record__external_id}-{label}", @@ -852,6 +875,10 @@ class IshtarSiteProfile(models.Model, Cached): "Change this with care. With incorrect formula, the " "application might be unusable and import of external " "data can be destructive.")) + find_complete_identifier = models.TextField( + _("Find complete identifier"), + default="", + help_text=_("Formula to manage find complete identifier.")) container_external_id = models.TextField( _("Container external id"), default="{parent_external_id}-{container_type__txt_idx}-" @@ -860,6 +887,10 @@ class IshtarSiteProfile(models.Model, Cached): "Change this with care. With incorrect formula, the " "application might be unusable and import of external " "data can be destructive.")) + container_complete_identifier = models.TextField( + _("Container complete identifier"), + default="", + help_text=_("Formula to manage container complete identifier.")) warehouse_external_id = models.TextField( _("Warehouse external id"), default="{name|slug}", @@ -867,6 +898,10 @@ class IshtarSiteProfile(models.Model, Cached): "Change this with care. With incorrect formula, the " "application might be unusable and import of external " "data can be destructive.")) + warehouse_complete_identifier = models.TextField( + _("Warehouse complete identifier"), + default="", + help_text=_("Formula to manage warehouse complete identifier.")) document_external_id = models.TextField( _("Document external id"), default="{index}", @@ -874,6 +909,10 @@ class IshtarSiteProfile(models.Model, Cached): "Change this with care. With incorrect formula, the " "application might be unusable and import of external " "data can be destructive.")) + document_complete_identifier = models.TextField( + _("Document complete identifier"), + default="", + help_text=_("Formula to manage document complete identifier.")) person_raw_name = models.TextField( _("Raw name for person"), default="{name|upper} {surname}", @@ -1902,7 +1941,7 @@ class Person(Address, Merge, OwnPerms, ValueGetter, MainItem): return self.cached_label or "" def _generate_cached_label(self): - lbl = get_external_id('person_raw_name', self) + lbl = get_generated_id('person_raw_name', self) if not lbl: return "-" if self.attached_to: @@ -2044,7 +2083,7 @@ class Person(Address, Merge, OwnPerms, ValueGetter, MainItem): def save(self, *args, **kwargs): super(Person, self).save(*args, **kwargs) - raw_name = get_external_id('person_raw_name', self) + raw_name = get_generated_id('person_raw_name', self) if raw_name and self.raw_name != raw_name: self.raw_name = raw_name self.save() @@ -2581,7 +2620,7 @@ post_save.connect(post_save_cache, sender=LicenseType) post_delete.connect(post_save_cache, sender=LicenseType) -class Document(BaseHistorizedItem, QRCodeItem, OwnPerms, ImageModel, +class Document(BaseHistorizedItem, CompleteIdentifierItem, OwnPerms, ImageModel, ValueGetter, MainItem): APP = "ishtar-common" MODEL = "document" diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index 20809e38e..8c5d60637 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -60,7 +60,7 @@ from ishtar_common.models_imports import Import from ishtar_common.templatetags.link_to_window import simple_link_to_window from ishtar_common.utils import get_cache, disable_for_loaddata, \ get_all_field_names, merge_tsvectors, cached_label_changed, post_save_geo, \ - task, duplicate_item, get_external_id, get_current_profile + task, duplicate_item, get_generated_id, get_current_profile """ from ishtar_common.models import get_external_id, \ @@ -1224,7 +1224,7 @@ class BaseHistorizedItem(StatisticItem, TemplateItem, FullSearch, Imported, self.external_id and not getattr(self, 'auto_external_id', False)): return - external_id = get_external_id(self.EXTERNAL_ID_KEY, self) + external_id = get_generated_id(self.EXTERNAL_ID_KEY, self) if external_id == self.external_id: return self.auto_external_id = True @@ -2641,8 +2641,9 @@ class ImageContainerModel: return "upload/{}/{:02d}/{:02d}".format(n.year, n.month, n.day) -class QRCodeItem(models.Model, ImageContainerModel): +class CompleteIdentifierItem(models.Model, ImageContainerModel): HAS_QR_CODE = True + complete_identifier = models.TextField(_("Complete identifier"), blank=True) qrcode = models.ImageField(upload_to=get_image_path, blank=True, null=True, max_length=255) @@ -2689,6 +2690,26 @@ class QRCodeItem(models.Model, ImageContainerModel): if tmpdir_created: shutil.rmtree(tmpdir) + def generate_complete_identifier(self): + SLUG = getattr(self, "SLUG", None) + if not SLUG: + return "" + complete_identifier = get_generated_id( + SLUG + "_complete_identifier", self) + if complete_identifier: + return complete_identifier + cached_label_key = 'cached_label' + if getattr(self, 'GEO_LABEL', None): + cached_label_key = getattr(self, 'GEO_LABEL', None) + if getattr(self, "CACHED_LABELS", None): + cached_label_key = getattr(self, "CACHED_LABELS")[-1] + complete_identifier = getattr(self, cached_label_key) + return complete_identifier + + def save(self, *args, **kwargs): + self.complete_identifier = self.generate_complete_identifier() + super(CompleteIdentifierItem, self).save(*args, **kwargs) + class SearchVectorConfig: def __init__(self, key, language=None, func=None): diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index 31459f861..70c374731 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -1782,8 +1782,7 @@ FORMULA_FILTERS = { 'deduplicate': _deduplicate } - -def get_external_id(key, item): +def get_generated_id(key, item): profile = get_current_profile() if not hasattr(profile, key): return |