#86 Log detail enhancements

* restructures removing of related data into separate sub-delete forms for easier logic handling
This commit is contained in:
2022-02-08 13:16:20 +01:00
parent 13fd3e1fcb
commit 6cdf355063
21 changed files with 206 additions and 75 deletions

View File

@@ -76,13 +76,3 @@ class CompensationAction(BaseResource):
if choice[0] == self.unit:
return choice[1]
return None
def delete(self, user=None, *args, **kwargs):
from compensation.models import Compensation
if user:
comps = Compensation.objects.filter(
actions__id__in=[self.id]
).distinct()
for comp in comps:
comp.mark_as_edited(user, edit_comment=COMPENSATION_ACTION_REMOVED)
super().delete(*args, **kwargs)

View File

@@ -21,7 +21,8 @@ from konova.models import BaseObject, AbstractDocument, Deadline, generate_docum
GeoReferencedMixin
from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE
from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, COMPENSATION_REMOVED_TEMPLATE, \
DOCUMENT_REMOVED_TEMPLATE, COMPENSATION_EDITED_TEMPLATE, DEADLINE_REMOVED, ADDED_DEADLINE
DOCUMENT_REMOVED_TEMPLATE, COMPENSATION_EDITED_TEMPLATE, DEADLINE_REMOVED, ADDED_DEADLINE, \
COMPENSATION_ACTION_REMOVED, COMPENSATION_STATE_REMOVED
from user.models import UserActionLogEntry
@@ -114,6 +115,21 @@ class AbstractCompensation(BaseObject, GeoReferencedMixin):
self.actions.add(comp_action)
return comp_action
def remove_action(self, form):
""" Removes a CompensationAction from the abstract compensation
Args:
form (CompensationActionRemoveModalForm): The form holding all relevant data
Returns:
"""
action = form.action
user = form.user
with transaction.atomic():
action.delete()
self.mark_as_edited(user, edit_comment=COMPENSATION_ACTION_REMOVED)
def add_state(self, form, is_before_state: bool) -> CompensationState:
""" Adds a new compensation state to the compensation
@@ -138,6 +154,21 @@ class AbstractCompensation(BaseObject, GeoReferencedMixin):
self.after_states.add(state)
return state
def remove_state(self, form):
""" Removes a CompensationState from the abstract compensation
Args:
form (CompensationStateRemoveModalForm): The form holding all relevant data
Returns:
"""
state = form.state
user = form.user
with transaction.atomic():
state.delete()
self.mark_as_edited(user, edit_comment=COMPENSATION_STATE_REMOVED)
def get_surface_after_states(self) -> float:
""" Calculates the compensation's/account's surface
@@ -346,7 +377,7 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin):
"""
self.intervention.unrecord(user, request)
action = super().mark_as_edited(user, edit_comment)
action = super().mark_as_edited(user, edit_comment=edit_comment)
return action
def is_ready_for_publish(self) -> bool:

View File

@@ -37,8 +37,3 @@ class Payment(BaseResource):
ordering = [
"-amount",
]
def delete(self, user=None, *args, **kwargs):
if user is not None:
self.intervention.mark_as_edited(user, edit_comment=PAYMENT_REMOVED)
super().delete(*args, **kwargs)

View File

@@ -47,14 +47,3 @@ class CompensationState(UuidModel):
def __str__(self):
return f"{self.biotope_type} | {self.surface}"
def delete(self, user=None, *args, **kwargs):
from compensation.models import Compensation
if user:
comps = Compensation.objects.filter(
Q(before_states__id__in=[self.id]) |
Q(after_states__id__in=[self.id])
).distinct()
for comp in comps:
comp.mark_as_edited(user, edit_comment=COMPENSATION_STATE_REMOVED)
super().delete(*args, **kwargs)