#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:
2022-02-03 15:29:22 +01:00
parent 0e48ae6e4a
commit 0a6d5cf19b
10 changed files with 231 additions and 160 deletions

View File

@@ -8,6 +8,8 @@ Created on: 22.07.21
from django.contrib import admin
from konova.models import Geometry, Deadline, GeometryConflict, Parcel, District
from konova.utils.message_templates import COMPENSATION_REMOVED_TEMPLATE
from user.models import UserAction
class GeometryAdmin(admin.ModelAdmin):
@@ -78,6 +80,9 @@ class BaseObjectAdmin(BaseResourceAdmin):
"identifier",
"title",
]
actions = [
"restore_deleted_data"
]
def get_fields(self, request, obj=None):
return super().get_fields(request, obj) + ["deleted"]
@@ -87,6 +92,21 @@ class BaseObjectAdmin(BaseResourceAdmin):
"deleted",
]
def restore_deleted_data(self, request, queryset):
queryset = queryset.filter(
deleted__isnull=False
)
for entry in queryset:
entry.deleted.delete()
# 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()
# Outcommented for a cleaner admin backend on production
#admin.site.register(Geometry, GeometryAdmin)

View File

@@ -21,6 +21,10 @@ CHECKED_RECORDED_RESET = _("Status of Checked and Recorded reseted")
# ECO ACCOUNT
CANCEL_ACC_RECORDED_OR_DEDUCTED = _("Action canceled. Eco account is recorded or deductions exist. Only conservation office member can perform this action.")
# COMPENSATION
COMPENSATION_ADDED_TEMPLATE = _("Compensation {} added")
COMPENSATION_REMOVED_TEMPLATE = _("Compensation {} removed")
# DEDUCTIONS
DEDUCTION_ADDED = _("Deduction added")
DEDUCTION_REMOVED = _("Deduction removed")