Skip to content

Commit

Permalink
Improve topologies in delete
Browse files Browse the repository at this point in the history
  • Loading branch information
LePetitTim committed Jun 3, 2022
1 parent d5f91e0 commit 45e6283
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions geotrek/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,14 @@ def save(self, *args, **kwargs):
def delete(self, *args, **kwargs):
if not settings.TREKKING_TOPOLOGY_ENABLED:
return super().delete(*args, **kwargs)
topologies = list(self.topology_set.filter())
if topologies and not settings.ALLOW_PATH_DELETION_TOPOLOGY:
topologies = self.topology_set.all()
if topologies.exists() and not settings.ALLOW_PATH_DELETION_TOPOLOGY:
raise ProtectedError(_("You can't delete this path, some topologies are linked with this path"), self)
topologies_list = list(topologies)
r = super().delete(*args, **kwargs)
if not Path.objects.exists():
return r
for topology in topologies:
for topology in topologies_list:
if isinstance(topology.geom, Point):
closest = self.closest(topology.geom, self)
position, offset = closest.interpolate(topology.geom)
Expand Down

0 comments on commit 45e6283

Please sign in to comment.