From 2957a6aa60064de770ea00fbeb9804a3cd7a7e23 Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Thu, 15 Sep 2022 12:12:35 +0200 Subject: [PATCH] 202 Geometry conflict checking to background * wraps check_for_conflicts() in celery based method * fixes bug on InterventionEditForm where geometry's save() has been called twice --- intervention/forms/intervention.py | 1 - konova/models/geometry.py | 3 ++- konova/tasks.py | 7 +++++++ konova/tests/test_geometries.py | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/intervention/forms/intervention.py b/intervention/forms/intervention.py index c62b3faa..00b772b1 100644 --- a/intervention/forms/intervention.py +++ b/intervention/forms/intervention.py @@ -372,7 +372,6 @@ class EditInterventionForm(NewInterventionForm): geometry = geom_form.save(user_action) self.instance.geometry = geometry - self.instance.geometry.save() self.instance.log.add(user_action) diff --git a/konova/models/geometry.py b/konova/models/geometry.py index e55082ac..6e7b0b6f 100644 --- a/konova/models/geometry.py +++ b/konova/models/geometry.py @@ -14,6 +14,7 @@ from django.utils import timezone from konova.models import BaseResource, UuidModel from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP +from konova.tasks import celery_check_for_geometry_conflicts from konova.utils.wfs.spatial import ParcelWFSFetcher @@ -28,7 +29,7 @@ class Geometry(BaseResource): def save(self, *args, **kwargs): super().save(*args, **kwargs) - self.check_for_conflicts() + celery_check_for_geometry_conflicts.delay(self.id) def check_for_conflicts(self): """ Checks for new geometry overlaps diff --git a/konova/tasks.py b/konova/tasks.py index 65801219..99618faf 100644 --- a/konova/tasks.py +++ b/konova/tasks.py @@ -120,3 +120,10 @@ def celery_send_mail_deduction_changed(obj_identifier, obj_title=None, user_id=N from user.models import User user = User.objects.get(id=user_id) user.send_mail_deduction_changed(obj_identifier, obj_title, data_changes) + + +@shared_task +def celery_check_for_geometry_conflicts(geom_id): + from konova.models import Geometry + geometry = Geometry.objects.get(id=geom_id) + geometry.check_for_conflicts() diff --git a/konova/tests/test_geometries.py b/konova/tests/test_geometries.py index 69a4ef71..e73070d8 100644 --- a/konova/tests/test_geometries.py +++ b/konova/tests/test_geometries.py @@ -47,6 +47,7 @@ class GeometryTestCase(BaseTestCase): Returns: """ + self.geom_2.check_for_conflicts() conflict = GeometryConflict.objects.all() self.assertEqual(1, conflict.count()) conflict = conflict.first() -- 2.45.2