diff options
Diffstat (limited to 'archaeological_operations/models.py')
| -rw-r--r-- | archaeological_operations/models.py | 22 | 
1 files changed, 11 insertions, 11 deletions
| diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 8fa72b423..40ee27fba 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -2069,10 +2069,10 @@ class Operation(      def post_save_geo(self, save=True):          # manage geodata towns -        if getattr(self, "_post_saved_geo", True): +        if getattr(self, "_post_save_geo_ok", False):              # prevent infinite loop - should not happen, but...              return -        self._post_saved_geo = True +        self._post_save_geo_ok = True          q_towns = self.towns.filter(main_geodata__multi_polygon__isnull=False)          q_towns_nb = q_towns.count()          q_geodata_town = self.geodata.filter( @@ -2097,21 +2097,21 @@ class Operation(                      self.main_geodata = None                  changed = True -        current_geo_town = None +        current_town_geo = None          if q_towns_nb == 1: -            current_geo_town = q_towns.all()[0] -            if not q_geodata_town.filter(pk=current_geo_town.pk).count(): -                for geo in q_geodata_town.all(): +            current_town_geo = q_towns.all()[0] +            if not q_geodata_town.filter(pk=current_town_geo.pk).count(): +                for geo in q_geodata_town.exclude(source_id=current_town_geo.pk).all():                      self.geodata.remove(geo)                      if self.main_geodata == geo:                          self.main_geodata = None -                self.geodata.add(current_geo_town) +                self.geodata.add(current_town_geo.main_geodata)                  changed = True          current_geo_area = None          if q_towns_nb > 1:              current_geo_area = Area.get_or_create_by_towns(q_towns, get_geo=True) -            if current_geo_area and not q_geodata_area.filter(pk=current_geo_area.pk).count(): +            if current_geo_area and not q_geodata_area.filter(source_id=current_geo_area.pk).count():                  for geo in q_geodata_area.all():                      self.geodata.remove(geo)                      if self.main_geodata == geo: @@ -2119,8 +2119,8 @@ class Operation(                  self.geodata.add(current_geo_area)                  changed = True -        if current_geo_town: -            q_extra_geo_town = q_geodata_town.exclude(pk=current_geo_town.pk) +        if current_town_geo: +            q_extra_geo_town = q_geodata_town.exclude(source_id=current_town_geo.pk)              if q_extra_geo_town.count():                  # should not occur but bad migrations, bad imports...                  for geo in q_extra_geo_town.all(): @@ -2129,7 +2129,7 @@ class Operation(                          self.main_geodata = None                  changed = True          if current_geo_area: -            q_extra_geo_area = q_geodata_area.exclude(pk=current_geo_area.pk) +            q_extra_geo_area = q_geodata_area.exclude(source_id=current_geo_area.pk)              if q_extra_geo_area.count():                  # should not occur but bad migrations, bad imports...                  for geo in q_extra_geo_area.all(): | 
