diff options
-rw-r--r-- | archaeological_finds/tests.py | 11 | ||||
-rw-r--r-- | archaeological_operations/models.py | 16 | ||||
-rw-r--r-- | archaeological_operations/wizards.py | 3 | ||||
-rw-r--r-- | ishtar_common/models.py | 1 | ||||
-rw-r--r-- | ishtar_common/wizards.py | 4 |
5 files changed, 28 insertions, 7 deletions
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py index 2e3026f6e..35471df00 100644 --- a/archaeological_finds/tests.py +++ b/archaeological_finds/tests.py @@ -319,8 +319,8 @@ class FindWizardModificationTest(WizardTest, FindInit, TestCase): FormData( 'Find modification', form_datas={ - 'selec': {'pk': ''}, - 'selecrecord': { + 'selec-find_modification': {'pk': ''}, + 'selecrecord-find_modification': { "get_first_base_find__context_record": "" }, 'find-find_modification': { @@ -350,9 +350,10 @@ class FindWizardModificationTest(WizardTest, FindInit, TestCase): find.save() data = self.form_datas[0].form_datas - data['selec']['pk'] = find.pk - data['selecrecord']['get_first_base_find__context_record'] = \ - find.base_finds.all()[0].pk + data['selec-find_modification']['pk'] = find.pk + data['selecrecord-find_modification'][ + 'get_first_base_find__context_record'] = \ + find.base_finds.all()[0].context_record.pk self.period = Period.objects.all()[0] self.period2 = Period.objects.all()[1] diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 014dbb269..368b2e33c 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -1739,6 +1739,18 @@ class Operation(ClosedItem, DocumentItem, BaseHistorizedItem, QRCodeItem, res['mode'] = " ; ".join([str(m) for m in mode(finds)]) return res + def clean_parcel_duplicates(self): + parcels = [] + for p in self.parcels.order_by('pk').all(): + if p.associated_file: + continue + key = (p.section, p.parcel_number, p.year, p.town.pk, + p.public_domain) + if key in parcels: + p.delete() + else: + parcels.append(key) + def save(self, *args, **kwargs): # put a default year if start_date is defined if self.start_date and not self.year: @@ -1747,7 +1759,9 @@ class Operation(ClosedItem, DocumentItem, BaseHistorizedItem, QRCodeItem, self.operation_code = self.get_available_operation_code(self.year) if hasattr(self, 'code_patriarche'): self.code_patriarche = self.code_patriarche or None - return super(Operation, self).save(*args, **kwargs) + item = super(Operation, self).save(*args, **kwargs) + self.clean_parcel_duplicates() + return item m2m_changed.connect(force_cached_label_changed, sender=Operation.towns.through) diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py index a37e923fb..fc5ce0bf8 100644 --- a/archaeological_operations/wizards.py +++ b/archaeological_operations/wizards.py @@ -277,6 +277,9 @@ class OperationWizard(Wizard): request.POST = post_data return super(OperationWizard, self).post(*args, **kwargs) + def post_save(self): + self.current_object.clean_parcel_duplicates() + class OperationModificationWizard(OperationWizard): modification = True diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 24d88edde..08ae93fa6 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -5709,7 +5709,6 @@ class Document(BaseHistorizedItem, QRCodeItem, OwnPerms, ImageModel, yield item._get_base_image_path() def _get_base_image_path(self): - print(5637) for path in self._get_base_image_paths(): if path: return path diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index db2cb7829..63f7ee30a 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -969,6 +969,7 @@ class Wizard(IshtarWizard): self.request.session[self.get_object_name(obj)] = str(obj.pk) dct = {'item': obj} self.current_object = obj + self.post_save() if self.redirect_url: url = reverse(self.redirect_url) @@ -985,6 +986,9 @@ class Wizard(IshtarWizard): res = render(self.request, self.wizard_done_template, dct) return return_object and (obj, res) or res + def post_save(self): + return + def get_deleted(self, keys): """ Get the deleted and non-deleted items in formsets |