summaryrefslogtreecommitdiff
path: root/archaeological_operations/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@proxience.com>2015-07-10 20:16:12 +0200
committerÉtienne Loks <etienne.loks@proxience.com>2015-07-10 20:16:12 +0200
commite412768a265d572a3bf8c01cb2827e32125ea11d (patch)
tree092c2cf03d9c336e24addf7d148aba1adadba441 /archaeological_operations/models.py
parente22efa3330e3682cfc35cc00d6fb254fab038a15 (diff)
downloadIshtar-e412768a265d572a3bf8c01cb2827e32125ea11d.tar.bz2
Ishtar-e412768a265d572a3bf8c01cb2827e32125ea11d.zip
Parcel management: copy non existing parcel from operation when associating a file
Diffstat (limited to 'archaeological_operations/models.py')
-rw-r--r--archaeological_operations/models.py35
1 files changed, 16 insertions, 19 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 6e74f2c44..e76de8dd9 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -428,25 +428,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)
@@ -467,6 +448,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):
@@ -715,6 +710,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:
@@ -737,6 +733,7 @@ class Parcel(LightHistorizedItem):
cr.parcel = self
cr.save()
parcel.delete()
+ """
@classmethod
def grouped_parcels(cls, parcels):