#86 Userlogs Compensation
* adds log details for adding/removing of compensations for intervention * adds handy restore-deleted function for admin backend for alls BaseObject derivatives * adds/updates translations
This commit is contained in:
@@ -18,7 +18,7 @@ from compensation.models import Compensation, EcoAccount
|
||||
from intervention.inputs import GenerateInput
|
||||
from intervention.models import Intervention, Responsibility, Legal
|
||||
from konova.forms import BaseForm, SimpleGeomForm
|
||||
from konova.utils.message_templates import EDITED_GENERAL_DATA
|
||||
from konova.utils.message_templates import EDITED_GENERAL_DATA, COMPENSATION_ADDED_TEMPLATE
|
||||
from user.models import UserActionLogEntry
|
||||
|
||||
|
||||
@@ -200,35 +200,49 @@ class NewCompensationForm(AbstractCompensationForm, CEFCompensationFormMixin, Co
|
||||
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:
|
||||
""" Creates the compensation from form data
|
||||
|
||||
Args:
|
||||
user (User): The performing user
|
||||
geom_form (SimpleGeomForm): The geometry form
|
||||
|
||||
Returns:
|
||||
comp (Compensation): The compensation object
|
||||
"""
|
||||
# Fetch data from cleaned POST values
|
||||
identifier = self.cleaned_data.get("identifier", None)
|
||||
title = self.cleaned_data.get("title", None)
|
||||
intervention = self.cleaned_data.get("intervention", None)
|
||||
is_cef = self.cleaned_data.get("is_cef", None)
|
||||
is_coherence_keeping = self.cleaned_data.get("is_coherence_keeping", None)
|
||||
comment = self.cleaned_data.get("comment", None)
|
||||
|
||||
# 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(
|
||||
identifier=identifier,
|
||||
title=title,
|
||||
intervention=intervention,
|
||||
created=action,
|
||||
is_cef=is_cef,
|
||||
is_coherence_keeping=is_coherence_keeping,
|
||||
geometry=geometry,
|
||||
comment=comment,
|
||||
)
|
||||
|
||||
# Add the log entry to the main objects log list
|
||||
comp.log.add(action)
|
||||
return comp
|
||||
|
||||
def save(self, user: User, geom_form: SimpleGeomForm):
|
||||
with transaction.atomic():
|
||||
# Fetch data from cleaned POST values
|
||||
identifier = self.cleaned_data.get("identifier", None)
|
||||
title = self.cleaned_data.get("title", None)
|
||||
intervention = self.cleaned_data.get("intervention", None)
|
||||
is_cef = self.cleaned_data.get("is_cef", None)
|
||||
is_coherence_keeping = self.cleaned_data.get("is_coherence_keeping", None)
|
||||
comment = self.cleaned_data.get("comment", None)
|
||||
|
||||
# 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(
|
||||
identifier=identifier,
|
||||
title=title,
|
||||
intervention=intervention,
|
||||
created=action,
|
||||
is_cef=is_cef,
|
||||
is_coherence_keeping=is_coherence_keeping,
|
||||
geometry=geometry,
|
||||
comment=comment,
|
||||
)
|
||||
|
||||
# Add the log entry to the main objects log list
|
||||
comp.log.add(action)
|
||||
comp = self.__create_comp(user, geom_form)
|
||||
comp.intervention.mark_as_edited(user, edit_comment=COMPENSATION_ADDED_TEMPLATE.format(comp.identifier))
|
||||
return comp
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ from compensation.utils.quality import CompensationQualityChecker
|
||||
from konova.models import BaseObject, AbstractDocument, Deadline, generate_document_file_upload_path, \
|
||||
GeoReferencedMixin
|
||||
from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE
|
||||
from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION
|
||||
from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, COMPENSATION_REMOVED_TEMPLATE
|
||||
from user.models import UserActionLogEntry
|
||||
|
||||
|
||||
@@ -235,6 +235,11 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin):
|
||||
self.identifier = self.generate_new_identifier()
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def mark_as_deleted(self, user, send_mail: bool = True):
|
||||
super().mark_as_deleted(user, send_mail)
|
||||
if user is not None:
|
||||
self.intervention.mark_as_edited(user, edit_comment=COMPENSATION_REMOVED_TEMPLATE.format(self.identifier))
|
||||
|
||||
def is_shared_with(self, user: User):
|
||||
""" Access check
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ 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
|
||||
CHECKED_RECORDED_RESET, COMPENSATION_ADDED_TEMPLATE, COMPENSATION_REMOVED_TEMPLATE
|
||||
from konova.utils.user_checks import in_group
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ def new_view(request: HttpRequest, intervention_id: str = None):
|
||||
comp.identifier
|
||||
)
|
||||
)
|
||||
messages.success(request, _("Compensation {} added").format(comp.identifier))
|
||||
messages.success(request, COMPENSATION_ADDED_TEMPLATE.format(comp.identifier))
|
||||
return redirect("compensation:detail", id=comp.id)
|
||||
else:
|
||||
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
||||
@@ -256,7 +256,7 @@ def remove_view(request: HttpRequest, id: str):
|
||||
form = RemoveModalForm(request.POST or None, instance=comp, request=request)
|
||||
return form.process_request(
|
||||
request=request,
|
||||
msg_success=_("Compensation removed"),
|
||||
msg_success=COMPENSATION_REMOVED_TEMPLATE.format(comp.identifier),
|
||||
redirect_url=reverse("compensation:index"),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user