Geometry race condition fix
* fixes race condition for geometry conflict and parcel calculation * harmonizes empty geometries from None/MultiPolygonEmpty to MultiPolygonEmpty
This commit is contained in:
@@ -129,12 +129,11 @@ class NewCompensationForm(AbstractCompensationForm,
|
||||
self.initialize_form_field("identifier", identifier)
|
||||
self.fields["identifier"].widget.attrs["url"] = reverse_lazy("compensation:new-id")
|
||||
|
||||
def __create_comp(self, user, geom_form) -> Compensation:
|
||||
def __create_comp(self, user):
|
||||
""" Creates the compensation from form data
|
||||
|
||||
Args:
|
||||
user (User): The performing user
|
||||
geom_form (SimpleGeomForm): The geometry form
|
||||
|
||||
Returns:
|
||||
comp (Compensation): The compensation object
|
||||
@@ -150,8 +149,6 @@ class NewCompensationForm(AbstractCompensationForm,
|
||||
|
||||
# Create log entry
|
||||
action = UserActionLogEntry.get_created_action(user)
|
||||
# Process the geometry form
|
||||
geometry = geom_form.save(action)
|
||||
|
||||
# Finally create main object
|
||||
comp = Compensation.objects.create(
|
||||
@@ -162,18 +159,23 @@ class NewCompensationForm(AbstractCompensationForm,
|
||||
is_cef=is_cef,
|
||||
is_coherence_keeping=is_coherence_keeping,
|
||||
is_pik=is_pik,
|
||||
geometry=geometry,
|
||||
comment=comment,
|
||||
)
|
||||
|
||||
# Add the log entry to the main objects log list
|
||||
comp.log.add(action)
|
||||
return comp
|
||||
return comp, action
|
||||
|
||||
def save(self, user: User, geom_form: SimpleGeomForm):
|
||||
with transaction.atomic():
|
||||
comp = self.__create_comp(user, geom_form)
|
||||
comp, action = self.__create_comp(user)
|
||||
comp.intervention.mark_as_edited(user, edit_comment=COMPENSATION_ADDED_TEMPLATE.format(comp.identifier))
|
||||
|
||||
# Process the geometry form
|
||||
geometry = geom_form.save(action)
|
||||
comp.geometry = geometry
|
||||
comp.save()
|
||||
|
||||
return comp
|
||||
|
||||
|
||||
@@ -205,6 +207,9 @@ class EditCompensationForm(NewCompensationForm):
|
||||
|
||||
def save(self, user: User, geom_form: SimpleGeomForm):
|
||||
with transaction.atomic():
|
||||
# Create log entry
|
||||
action = UserActionLogEntry.get_edited_action(user)
|
||||
|
||||
# Fetch data from cleaned POST values
|
||||
identifier = self.cleaned_data.get("identifier", None)
|
||||
title = self.cleaned_data.get("title", None)
|
||||
@@ -214,17 +219,9 @@ class EditCompensationForm(NewCompensationForm):
|
||||
is_pik = self.cleaned_data.get("is_pik", None)
|
||||
comment = self.cleaned_data.get("comment", None)
|
||||
|
||||
# Create log entry
|
||||
action = UserActionLogEntry.get_edited_action(user)
|
||||
|
||||
# Process the geometry form
|
||||
geometry = geom_form.save(action)
|
||||
|
||||
# Finally create main object
|
||||
self.instance.identifier = identifier
|
||||
self.instance.title = title
|
||||
self.instance.intervention = intervention
|
||||
self.instance.geometry = geometry
|
||||
self.instance.is_cef = is_cef
|
||||
self.instance.is_coherence_keeping = is_coherence_keeping
|
||||
self.instance.comment = comment
|
||||
@@ -233,6 +230,11 @@ class EditCompensationForm(NewCompensationForm):
|
||||
self.instance.save()
|
||||
|
||||
self.instance.log.add(action)
|
||||
|
||||
intervention.mark_as_edited(user, self.request, EDITED_GENERAL_DATA)
|
||||
return self.instance
|
||||
|
||||
# Process the geometry form (NOT ATOMIC TRANSACTION DUE TO CELERY!)
|
||||
geometry = geom_form.save(action)
|
||||
self.instance.geometry = geometry
|
||||
self.instance.save()
|
||||
|
||||
return self.instance
|
||||
|
||||
@@ -94,8 +94,6 @@ class NewEcoAccountForm(AbstractCompensationForm, CompensationResponsibleFormMix
|
||||
|
||||
# Create log entry
|
||||
action = UserActionLogEntry.get_created_action(user)
|
||||
# Process the geometry form
|
||||
geometry = geom_form.save(action)
|
||||
|
||||
handler = Handler.objects.create(
|
||||
type=handler_type,
|
||||
@@ -119,7 +117,6 @@ class NewEcoAccountForm(AbstractCompensationForm, CompensationResponsibleFormMix
|
||||
responsible=responsible,
|
||||
deductable_surface=surface,
|
||||
created=action,
|
||||
geometry=geometry,
|
||||
comment=comment,
|
||||
is_pik=is_pik,
|
||||
legal=legal
|
||||
@@ -129,6 +126,10 @@ class NewEcoAccountForm(AbstractCompensationForm, CompensationResponsibleFormMix
|
||||
# Add the log entry to the main objects log list
|
||||
acc.log.add(action)
|
||||
|
||||
# Process the geometry form
|
||||
geometry = geom_form.save(action)
|
||||
acc.geometry = geometry
|
||||
acc.save()
|
||||
acc.update_deductable_rest()
|
||||
return acc
|
||||
|
||||
@@ -185,9 +186,6 @@ class EditEcoAccountForm(NewEcoAccountForm):
|
||||
# Create log entry
|
||||
action = UserActionLogEntry.get_edited_action(user)
|
||||
|
||||
# Process the geometry form
|
||||
geometry = geom_form.save(action)
|
||||
|
||||
# Update responsible data
|
||||
self.instance.responsible.handler.type = handler_type
|
||||
self.instance.responsible.handler.detail = handler_detail
|
||||
@@ -204,7 +202,6 @@ class EditEcoAccountForm(NewEcoAccountForm):
|
||||
self.instance.identifier = identifier
|
||||
self.instance.title = title
|
||||
self.instance.deductable_surface = surface
|
||||
self.instance.geometry = geometry
|
||||
self.instance.comment = comment
|
||||
self.instance.is_pik = is_pik
|
||||
self.instance.modified = action
|
||||
@@ -213,6 +210,10 @@ class EditEcoAccountForm(NewEcoAccountForm):
|
||||
# Add the log entry to the main objects log list
|
||||
self.instance.log.add(action)
|
||||
|
||||
# Process the geometry form (NOT ATOMIC TRANSACTION DUE TO CELERY!)
|
||||
geometry = geom_form.save(action)
|
||||
self.instance.geometry = geometry
|
||||
self.instance.save()
|
||||
self.instance.update_deductable_rest()
|
||||
return self.instance
|
||||
|
||||
|
||||
Reference in New Issue
Block a user