diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-09-20 13:45:27 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-09-20 13:45:27 +0200 |
commit | 03cb63b9b6c5d0d2a63088528da24f187457f4a1 (patch) | |
tree | fd072535b325d65f12e415e6582cf7a073775999 /archaeological_operations | |
parent | 5e55409037f385cdbd01710ea11af9cb9584fd9a (diff) | |
download | Ishtar-03cb63b9b6c5d0d2a63088528da24f187457f4a1.tar.bz2 Ishtar-03cb63b9b6c5d0d2a63088528da24f187457f4a1.zip |
Fix external id generation for finds
Diffstat (limited to 'archaeological_operations')
-rw-r--r-- | archaeological_operations/models.py | 23 | ||||
-rw-r--r-- | archaeological_operations/tests.py | 19 |
2 files changed, 32 insertions, 10 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 1f4108c28..44f7a529e 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -37,7 +37,7 @@ from ishtar_common.models import GeneralType, BaseHistorizedItem, \ SourceType, Person, Organization, Town, Dashboard, IshtarUser, ValueGetter,\ DocumentTemplate, ShortMenuItem, DashboardFormItem, GeneralRelationType,\ GeneralRecordRelations, post_delete_record_relation, OperationType, \ - get_external_id, ImageModel, post_save_cache + get_external_id, ImageModel, post_save_cache, ExternalIdManager class RemainType(GeneralType): @@ -815,6 +815,15 @@ def operation_post_save(sender, **kwargs): # manage parcel association for parcel in operation.parcels.all(): parcel.copy_to_file() + + # external id update + for parcel in operation.parcels.all(): + parcel.update_external_id() + + for cr in operation.context_record.all(): + cr.update_external_id() + + post_save.connect(operation_post_save, sender=Operation) @@ -839,6 +848,7 @@ class RecordRelations(GeneralRecordRelations, models.Model): verbose_name_plural = _(u"Operation record relations") ordering = ('left_record', 'relation_type') + post_delete.connect(post_delete_record_relation, sender=RecordRelations) @@ -1245,7 +1255,9 @@ def strip_zero(value): return value -class Parcel(LightHistorizedItem): +class Parcel(ExternalIdManager, LightHistorizedItem): + EXTERNAL_ID_KEY = 'parcel_external_id' + associated_file = models.ForeignKey( 'archaeological_files.File', related_name='parcels', verbose_name=_(u"File"), @@ -1426,13 +1438,6 @@ def parcel_post_save(sender, **kwargs): parcel.delete() return - if not parcel.external_id or parcel.auto_external_id: - external_id = get_external_id('parcel_external_id', parcel) - if external_id != parcel.external_id: - updated = True - parcel._updated_id = True - parcel.auto_external_id = True - parcel.external_id = external_id if updated: parcel.save() return diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 60078b7e2..0d6908374 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -1245,6 +1245,7 @@ class OperationWizardCreationTest(WizardTest, OperationInitTest, TestCase): form_datas={ 'filechoice': {}, 'general': { + 'code_patriarche': 'codeope1', 'operation_type': None, 'year': 2016}, 'townsgeneral': [], @@ -1259,6 +1260,7 @@ class OperationWizardCreationTest(WizardTest, OperationInitTest, TestCase): form_datas={ 'filechoice': {}, 'general': { + 'code_patriarche': 'codeope2', 'operation_type': None, 'year': 2016}, 'townsgeneral': [], @@ -1273,6 +1275,7 @@ class OperationWizardCreationTest(WizardTest, OperationInitTest, TestCase): form_datas={ 'filechoice': {}, 'general': { + 'code_patriarche': 'codeope3', 'operation_type': None, 'year': 2016}, 'towns': [], @@ -1332,8 +1335,17 @@ class OperationWizardCreationTest(WizardTest, OperationInitTest, TestCase): def post_wizard(self): self.assertEqual(models.Operation.objects.count(), self.operation_number + 3) + operations = models.Operation.objects.order_by("-pk").all()[:3] + + parcel_ids = [] + for operation in operations: + for parcel in operation.parcels.all(): + parcel_ids.append(parcel.external_id) + self.assertEqual(list(sorted(parcel_ids)), + ['codeope1-12345-S42', 'codeope2-12345-S42', + 'codeope3-12345-G43']) self.assertEqual(models.Parcel.objects.count(), - self.parcel_number + 2) + self.parcel_number + 3) class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase): @@ -1369,6 +1381,7 @@ class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase): form_datas={ 'selec': {}, 'general': { + 'code_patriarche': "codeope42", 'operation_type': 2, 'year': 2017}, 'townsgeneral': [], @@ -1470,6 +1483,10 @@ class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase): # the init parcel is not detached from the operation test_object.assertEqual(operation.parcels.count(), test_object.parcel_number + 1) + # update teh external id on update + cr = ContextRecord.objects.get(pk=self.cr.pk) + test_object.assertEqual(cr.external_id, + "codeope42-12345-A1-Context record") def pre_third_wizard(test_object): parcel_nb = models.Parcel.objects.count() |