parent
e5153ddf77
commit
7535f008b7
@ -12,6 +12,7 @@ from codelist.models import KonovaCode
|
||||
from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_COMPENSATION_ACTION_DETAIL_ID
|
||||
from compensation.managers import CompensationActionManager
|
||||
from konova.models import BaseResource
|
||||
from konova.utils.message_templates import COMPENSATION_ACTION_REMOVED
|
||||
|
||||
|
||||
class UnitChoices(models.TextChoices):
|
||||
@ -75,3 +76,13 @@ 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)
|
@ -21,7 +21,7 @@ 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
|
||||
DOCUMENT_REMOVED_TEMPLATE, COMPENSATION_EDITED_TEMPLATE
|
||||
from user.models import UserActionLogEntry
|
||||
|
||||
|
||||
@ -61,7 +61,6 @@ class AbstractCompensation(BaseObject, GeoReferencedMixin):
|
||||
user = form.user
|
||||
with transaction.atomic():
|
||||
created_action = UserActionLogEntry.get_created_action(user)
|
||||
edited_action = UserActionLogEntry.get_edited_action(user, _("Added deadline"))
|
||||
|
||||
deadline = Deadline.objects.create(
|
||||
type=form_data["type"],
|
||||
@ -70,9 +69,7 @@ class AbstractCompensation(BaseObject, GeoReferencedMixin):
|
||||
created=created_action,
|
||||
)
|
||||
|
||||
self.modified = edited_action
|
||||
self.save()
|
||||
self.log.add(edited_action)
|
||||
self.deadlines.add(deadline)
|
||||
return deadline
|
||||
|
||||
@ -332,7 +329,9 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin):
|
||||
Returns:
|
||||
|
||||
"""
|
||||
return self.intervention.mark_as_edited(user, request, edit_comment, reset_recorded)
|
||||
self.intervention.unrecord(user, request)
|
||||
action = super().mark_as_edited(user, edit_comment)
|
||||
return action
|
||||
|
||||
def is_ready_for_publish(self) -> bool:
|
||||
""" Not inherited by RecordableObjectMixin
|
||||
|
@ -273,5 +273,5 @@ class EcoAccountDeduction(BaseResource):
|
||||
def delete(self, user=None, *args, **kwargs):
|
||||
if user is not None:
|
||||
self.intervention.mark_as_edited(user, edit_comment=DEDUCTION_REMOVED)
|
||||
self.account.mark_as_edited(user, edit_comment=DEDUCTION_REMOVED, reset_recorded=False)
|
||||
self.account.mark_as_edited(user, edit_comment=DEDUCTION_REMOVED)
|
||||
super().delete(*args, **kwargs)
|
@ -6,11 +6,13 @@ Created on: 16.11.21
|
||||
|
||||
"""
|
||||
from django.db import models
|
||||
from django.db.models import Q
|
||||
|
||||
from codelist.models import KonovaCode
|
||||
from codelist.settings import CODELIST_BIOTOPES_ID, CODELIST_BIOTOPES_EXTRA_CODES_ID
|
||||
from compensation.managers import CompensationStateManager
|
||||
from konova.models import UuidModel
|
||||
from konova.utils.message_templates import COMPENSATION_STATE_REMOVED
|
||||
|
||||
|
||||
class CompensationState(UuidModel):
|
||||
@ -45,3 +47,14 @@ class CompensationState(UuidModel):
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.biotope_type} | {self.surface} m²"
|
||||
|
||||
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)
|
||||
|
@ -18,7 +18,8 @@ from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
||||
from konova.utils.documents import get_document, remove_document
|
||||
from konova.utils.generators import generate_qr_code
|
||||
from konova.utils.message_templates import FORM_INVALID, IDENTIFIER_REPLACED, DATA_UNSHARED_EXPLANATION, \
|
||||
CHECKED_RECORDED_RESET, COMPENSATION_ADDED_TEMPLATE, COMPENSATION_REMOVED_TEMPLATE, DOCUMENT_ADDED
|
||||
CHECKED_RECORDED_RESET, COMPENSATION_ADDED_TEMPLATE, COMPENSATION_REMOVED_TEMPLATE, DOCUMENT_ADDED, \
|
||||
COMPENSATION_STATE_REMOVED, COMPENSATION_STATE_ADDED, COMPENSATION_ACTION_REMOVED, COMPENSATION_ACTION_ADDED
|
||||
from konova.utils.user_checks import in_group
|
||||
|
||||
|
||||
@ -347,7 +348,7 @@ def state_new_view(request: HttpRequest, id: str):
|
||||
form = NewStateModalForm(request.POST or None, instance=comp, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("State added"),
|
||||
msg_success=COMPENSATION_STATE_ADDED,
|
||||
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
|
||||
@ -369,7 +370,7 @@ def action_new_view(request: HttpRequest, id: str):
|
||||
form = NewActionModalForm(request.POST or None, instance=comp, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Action added"),
|
||||
msg_success=COMPENSATION_ACTION_ADDED,
|
||||
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
|
||||
@ -437,7 +438,7 @@ def state_remove_view(request: HttpRequest, id: str, state_id: str):
|
||||
form = RemoveModalForm(request.POST or None, instance=state, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("State removed"),
|
||||
msg_success=COMPENSATION_STATE_REMOVED,
|
||||
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
|
||||
@ -460,7 +461,7 @@ def action_remove_view(request: HttpRequest, id: str, action_id: str):
|
||||
form = RemoveModalForm(request.POST or None, instance=action, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Action removed"),
|
||||
msg_success=COMPENSATION_ACTION_REMOVED,
|
||||
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
|
||||
|
@ -30,7 +30,8 @@ from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
||||
from konova.utils.documents import get_document, remove_document
|
||||
from konova.utils.generators import generate_qr_code
|
||||
from konova.utils.message_templates import IDENTIFIER_REPLACED, FORM_INVALID, DATA_UNSHARED, DATA_UNSHARED_EXPLANATION, \
|
||||
CANCEL_ACC_RECORDED_OR_DEDUCTED, DEDUCTION_REMOVED, DEDUCTION_ADDED, DOCUMENT_ADDED
|
||||
CANCEL_ACC_RECORDED_OR_DEDUCTED, DEDUCTION_REMOVED, DEDUCTION_ADDED, DOCUMENT_ADDED, COMPENSATION_STATE_REMOVED, \
|
||||
COMPENSATION_STATE_ADDED, COMPENSATION_ACTION_REMOVED, COMPENSATION_ACTION_ADDED
|
||||
from konova.utils.user_checks import in_group
|
||||
|
||||
|
||||
@ -359,7 +360,7 @@ def state_new_view(request: HttpRequest, id: str):
|
||||
form = NewStateModalForm(request.POST or None, instance=acc, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("State added"),
|
||||
msg_success=COMPENSATION_STATE_ADDED,
|
||||
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
|
||||
@ -381,7 +382,7 @@ def action_new_view(request: HttpRequest, id: str):
|
||||
form = NewActionModalForm(request.POST or None, instance=acc, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Action added"),
|
||||
msg_success=COMPENSATION_ACTION_ADDED,
|
||||
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
|
||||
@ -404,7 +405,7 @@ def state_remove_view(request: HttpRequest, id: str, state_id: str):
|
||||
form = RemoveModalForm(request.POST or None, instance=state, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("State removed"),
|
||||
msg_success=COMPENSATION_STATE_REMOVED,
|
||||
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
|
||||
@ -427,7 +428,7 @@ def action_remove_view(request: HttpRequest, id: str, action_id: str):
|
||||
form = RemoveModalForm(request.POST or None, instance=action, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Action removed"),
|
||||
msg_success=COMPENSATION_ACTION_REMOVED,
|
||||
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
|
||||
|
11
ema/views.py
11
ema/views.py
@ -21,7 +21,8 @@ from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
||||
from konova.utils.documents import get_document, remove_document
|
||||
from konova.utils.generators import generate_qr_code
|
||||
from konova.utils.message_templates import IDENTIFIER_REPLACED, FORM_INVALID, DATA_UNSHARED, DATA_UNSHARED_EXPLANATION, \
|
||||
DOCUMENT_ADDED
|
||||
DOCUMENT_ADDED, COMPENSATION_STATE_REMOVED, COMPENSATION_STATE_ADDED, COMPENSATION_ACTION_REMOVED, \
|
||||
COMPENSATION_ACTION_ADDED
|
||||
from konova.utils.user_checks import in_group
|
||||
|
||||
|
||||
@ -292,7 +293,7 @@ def state_new_view(request: HttpRequest, id: str):
|
||||
form = NewStateModalForm(request.POST or None, instance=ema, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("State added"),
|
||||
msg_success=COMPENSATION_STATE_ADDED,
|
||||
redirect_url=reverse("ema:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
|
||||
@ -314,7 +315,7 @@ def action_new_view(request: HttpRequest, id: str):
|
||||
form = NewActionModalForm(request.POST or None, instance=ema, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Action added"),
|
||||
msg_success=COMPENSATION_ACTION_ADDED,
|
||||
redirect_url=reverse("ema:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
|
||||
@ -428,7 +429,7 @@ def state_remove_view(request: HttpRequest, id: str, state_id: str):
|
||||
form = RemoveModalForm(request.POST or None, instance=state, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("State removed"),
|
||||
msg_success=COMPENSATION_STATE_REMOVED,
|
||||
redirect_url=reverse("ema:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
|
||||
@ -451,7 +452,7 @@ def action_remove_view(request: HttpRequest, id: str, action_id: str):
|
||||
form = RemoveModalForm(request.POST or None, instance=action, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Action removed"),
|
||||
msg_success=COMPENSATION_ACTION_REMOVED,
|
||||
redirect_url=reverse("ema:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
|
||||
|
@ -386,7 +386,7 @@ class NewDeductionModalForm(BaseModalForm):
|
||||
def save(self):
|
||||
deduction = self.__create_deduction()
|
||||
self.cleaned_data["intervention"].mark_as_edited(self.user, edit_comment=DEDUCTION_ADDED)
|
||||
self.cleaned_data["account"].mark_as_edited(self.user, edit_comment=DEDUCTION_ADDED, reset_recorded=False)
|
||||
self.cleaned_data["account"].mark_as_edited(self.user, edit_comment=DEDUCTION_ADDED)
|
||||
return deduction
|
||||
|
||||
|
||||
|
@ -242,7 +242,9 @@ class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, Chec
|
||||
Returns:
|
||||
|
||||
"""
|
||||
action = super().mark_as_edited(performing_user, request, edit_comment, reset_recorded)
|
||||
action = super().mark_as_edited(performing_user, edit_comment)
|
||||
if reset_recorded:
|
||||
self.unrecord(performing_user, request)
|
||||
if self.checked:
|
||||
self.set_unchecked()
|
||||
return action
|
||||
|
@ -132,6 +132,23 @@ class BaseObject(BaseResource):
|
||||
|
||||
self.save()
|
||||
|
||||
def mark_as_edited(self, performing_user: User, edit_comment: str = None):
|
||||
""" In case the object or a related object changed the log history needs to be updated
|
||||
|
||||
Args:
|
||||
performing_user (User): The user which performed the editing action
|
||||
request (HttpRequest): The used request for this action
|
||||
edit_comment (str): Additional comment for the log entry
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
edit_action = UserActionLogEntry.get_edited_action(performing_user, edit_comment)
|
||||
self.modified = edit_action
|
||||
self.log.add(edit_action)
|
||||
self.save()
|
||||
return edit_action
|
||||
|
||||
def add_log_entry(self, action: UserAction, user: User, comment: str):
|
||||
""" Wraps adding of UserActionLogEntry to log
|
||||
|
||||
@ -262,25 +279,18 @@ class RecordableObjectMixin(models.Model):
|
||||
|
||||
return action
|
||||
|
||||
def mark_as_edited(self, performing_user: User, request: HttpRequest = None, edit_comment: str = None, reset_recorded: bool = True):
|
||||
""" In case the object or a related object changed, internal processes need to be started, such as
|
||||
unrecord and uncheck
|
||||
def unrecord(self, performing_user: User, request: HttpRequest = None):
|
||||
""" Unrecords a dataset
|
||||
|
||||
Args:
|
||||
performing_user (User): The user which performed the editing action
|
||||
request (HttpRequest): The used request for this action
|
||||
edit_comment (str): Additional comment for the log entry
|
||||
reset_recorded (bool): Whether the record-state of the object should be reset
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
edit_action = UserActionLogEntry.get_edited_action(performing_user, edit_comment)
|
||||
self.modified = edit_action
|
||||
self.log.add(edit_action)
|
||||
self.save()
|
||||
|
||||
if self.recorded and reset_recorded:
|
||||
action = None
|
||||
if self.recorded:
|
||||
action = self.set_unrecorded(performing_user)
|
||||
self.log.add(action)
|
||||
if request:
|
||||
@ -288,7 +298,7 @@ class RecordableObjectMixin(models.Model):
|
||||
request,
|
||||
CHECKED_RECORDED_RESET
|
||||
)
|
||||
return edit_action
|
||||
return action
|
||||
|
||||
@abstractmethod
|
||||
def is_ready_for_publish(self) -> bool:
|
||||
|
@ -24,6 +24,17 @@ CANCEL_ACC_RECORDED_OR_DEDUCTED = _("Action canceled. Eco account is recorded or
|
||||
# COMPENSATION
|
||||
COMPENSATION_ADDED_TEMPLATE = _("Compensation {} added")
|
||||
COMPENSATION_REMOVED_TEMPLATE = _("Compensation {} removed")
|
||||
COMPENSATION_EDITED_TEMPLATE = _("Compensation {} edited")
|
||||
ADDED_COMPENSATION_ACTION = _("Added compensation action")
|
||||
ADDED_COMPENSATION_STATE = _("Added compensation state")
|
||||
|
||||
# COMPENSATION STATE
|
||||
COMPENSATION_STATE_REMOVED = _("State removed")
|
||||
COMPENSATION_STATE_ADDED = _("State added")
|
||||
|
||||
# COMPENSATION ACTION
|
||||
COMPENSATION_ACTION_ADDED = _("Action added")
|
||||
COMPENSATION_ACTION_REMOVED = _("Action removed")
|
||||
|
||||
# DEDUCTIONS
|
||||
DEDUCTION_ADDED = _("Deduction added")
|
||||
@ -43,9 +54,7 @@ DOCUMENT_ADDED = _("Document added")
|
||||
|
||||
# Edited
|
||||
EDITED_GENERAL_DATA = _("Edited general data")
|
||||
ADDED_COMPENSATION_STATE = _("Added compensation state")
|
||||
ADDED_DEADLINE = _("Added deadline")
|
||||
ADDED_COMPENSATION_ACTION = _("Added compensation action")
|
||||
|
||||
# Geometry conflicts
|
||||
GEOMETRY_CONFLICT_WITH_TEMPLATE = _("Geometry conflict detected with {}")
|
||||
|
Loading…
Reference in New Issue
Block a user