diff options
Diffstat (limited to 'archaeological_operations/models.py')
-rw-r--r-- | archaeological_operations/models.py | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 8f69dd2e0..f13ee4ca9 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -435,25 +435,6 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem, # put a default year if start_date is defined if self.start_date and not self.year: self.year = self.start_date.year - # manage parcel association - """ - if FILES_AVAILABLE and self.associated_file: - for parcel in self.associated_file.parcels.exclude( - operation=self).all(): - parcel.operation = self - parcel.save() - for parcel in self.parcels.exclude( - associated_file=self.associated_file).all(): - parcel.associated_file = self.associated_file - parcel.save() - parcels = {} - for parcel in self.parcels.all(): - keys = (parcel.town, parcel.section, parcel.parcel_number) - if keys in parcels.keys(): - parcel.merge(parcels[keys]) - else: - parcels[keys] = parcel - """ return super(Operation, self).save(*args, **kwargs) m2m_changed.connect(cached_label_changed, sender=Operation.towns.through) @@ -474,6 +455,20 @@ def operation_post_save(sender, **kwargs): cached_label_changed(sender, **kwargs) if FILES_AVAILABLE and operation.associated_file: operation.associated_file.update_short_menu_class() + # manage parcel association + if FILES_AVAILABLE and operation.associated_file: + for parcel in operation.parcels.all(): + keys = {'town':parcel.town, 'section':parcel.section, + 'parcel_number':parcel.parcel_number} + if not operation.associated_file.parcels.filter(**keys).count(): + keys['address'] = parcel.address + keys['year'] = parcel.year + keys['associated_file'] = operation.associated_file + new_p = Parcel.objects.create(**keys) + for owning in parcel.owners.all(): + ParcelOwner.objects.create(owner=owning.owner, + parcel=new_p, start_date=owning.start_date, + end_date=owning.end_date) post_save.connect(operation_post_save, sender=Operation) class OperationByDepartment(models.Model): @@ -723,6 +718,7 @@ class Parcel(LightHistorizedItem): def __unicode__(self): return self.short_label + """ def merge(self, parcel): # cannot automatically merge if self.address and parcel.address and self.address != parcel.address: @@ -745,6 +741,7 @@ class Parcel(LightHistorizedItem): cr.parcel = self cr.save() parcel.delete() + """ @classmethod def grouped_parcels(cls, parcels): |