# 86 More log details Documents
* adds more log details on adding/removing documents * fixes bug in admin backend where restoring of non-compensation entries led to an error * fixes bug where deleting of revocation without an attached file would lead to an error
This commit is contained in:
@@ -3,6 +3,8 @@ from django.contrib import admin
|
||||
from compensation.models import Compensation, CompensationAction, CompensationState, Payment, \
|
||||
EcoAccountDeduction, EcoAccount
|
||||
from konova.admin import BaseObjectAdmin, BaseResourceAdmin
|
||||
from konova.utils.message_templates import COMPENSATION_REMOVED_TEMPLATE
|
||||
from user.models import UserAction
|
||||
|
||||
|
||||
class AbstractCompensationAdmin(BaseObjectAdmin):
|
||||
@@ -42,6 +44,17 @@ class CompensationAdmin(AbstractCompensationAdmin):
|
||||
"intervention",
|
||||
]
|
||||
|
||||
def restore_deleted_data(self, request, queryset):
|
||||
super().restore_deleted_data(request, queryset)
|
||||
|
||||
for entry in queryset:
|
||||
# Remove delete log entry from related intervention log history
|
||||
logs = entry.intervention.log.filter(
|
||||
action=UserAction.EDITED,
|
||||
comment=COMPENSATION_REMOVED_TEMPLATE.format(entry.identifier)
|
||||
)
|
||||
logs.delete()
|
||||
|
||||
|
||||
class EcoAccountAdmin(AbstractCompensationAdmin):
|
||||
list_display = [
|
||||
|
||||
@@ -20,7 +20,8 @@ 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, COMPENSATION_REMOVED_TEMPLATE
|
||||
from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, COMPENSATION_REMOVED_TEMPLATE, \
|
||||
DOCUMENT_REMOVED_TEMPLATE
|
||||
from user.models import UserActionLogEntry
|
||||
|
||||
|
||||
@@ -358,7 +359,7 @@ class CompensationDocument(AbstractDocument):
|
||||
max_length=1000,
|
||||
)
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
def delete(self, user=None, *args, **kwargs):
|
||||
"""
|
||||
Custom delete functionality for CompensationDocuments.
|
||||
Removes the folder from the file system if there are no further documents for this entry.
|
||||
@@ -380,6 +381,9 @@ class CompensationDocument(AbstractDocument):
|
||||
folder_path = self.file.path.split("/")[:-1]
|
||||
folder_path = "/".join(folder_path)
|
||||
|
||||
if user:
|
||||
self.instance.mark_as_edited(user, edit_comment=DOCUMENT_REMOVED_TEMPLATE.format(self.title))
|
||||
|
||||
# Remove the file itself
|
||||
super().delete(*args, **kwargs)
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import shutil
|
||||
|
||||
from django.urls import reverse
|
||||
|
||||
from konova.utils.message_templates import DEDUCTION_REMOVED
|
||||
from konova.utils.message_templates import DEDUCTION_REMOVED, DOCUMENT_REMOVED_TEMPLATE
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.validators import MinValueValidator
|
||||
from django.db import models
|
||||
@@ -199,7 +199,7 @@ class EcoAccountDocument(AbstractDocument):
|
||||
max_length=1000,
|
||||
)
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
def delete(self, user=None, *args, **kwargs):
|
||||
"""
|
||||
Custom delete functionality for EcoAccountDocuments.
|
||||
Removes the folder from the file system if there are no further documents for this entry.
|
||||
@@ -221,6 +221,9 @@ class EcoAccountDocument(AbstractDocument):
|
||||
folder_path = self.file.path.split("/")[:-1]
|
||||
folder_path = "/".join(folder_path)
|
||||
|
||||
if user:
|
||||
self.instance.mark_as_edited(user, edit_comment=DOCUMENT_REMOVED_TEMPLATE.format(self.title))
|
||||
|
||||
# Remove the file itself
|
||||
super().delete(*args, **kwargs)
|
||||
|
||||
|
||||
@@ -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, COMPENSATION_ADDED_TEMPLATE, COMPENSATION_REMOVED_TEMPLATE
|
||||
CHECKED_RECORDED_RESET, COMPENSATION_ADDED_TEMPLATE, COMPENSATION_REMOVED_TEMPLATE, DOCUMENT_ADDED
|
||||
from konova.utils.user_checks import in_group
|
||||
|
||||
|
||||
@@ -277,7 +277,7 @@ def new_document_view(request: HttpRequest, id: str):
|
||||
form = NewCompensationDocumentForm(request.POST or None, request.FILES or None, instance=comp, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Document added"),
|
||||
msg_success=DOCUMENT_ADDED,
|
||||
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
|
||||
|
||||
@@ -30,7 +30,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 IDENTIFIER_REPLACED, FORM_INVALID, DATA_UNSHARED, DATA_UNSHARED_EXPLANATION, \
|
||||
CANCEL_ACC_RECORDED_OR_DEDUCTED, DEDUCTION_REMOVED, DEDUCTION_ADDED
|
||||
CANCEL_ACC_RECORDED_OR_DEDUCTED, DEDUCTION_REMOVED, DEDUCTION_ADDED, DOCUMENT_ADDED
|
||||
from konova.utils.user_checks import in_group
|
||||
|
||||
|
||||
@@ -493,7 +493,7 @@ def new_document_view(request: HttpRequest, id: str):
|
||||
form = NewEcoAccountDocumentForm(request.POST or None, request.FILES or None, instance=acc, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Document added"),
|
||||
msg_success=DOCUMENT_ADDED,
|
||||
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data",
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user