Log
* adds modal_generic.html template for generic usage * adds M2M field log to BaseObject * adds show log button to controls.html * adds logging on adding related objects * adds render log table using generic modal * adds tooltip to missing values in detail views * adds/updates translations
This commit is contained in:
@@ -21,7 +21,7 @@ from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from konova.contexts import BaseContext
|
||||
from konova.models import Document
|
||||
from konova.models import Document, BaseObject
|
||||
from konova.utils.message_templates import FORM_INVALID
|
||||
from user.models import UserActionLogEntry, UserAction
|
||||
|
||||
@@ -236,14 +236,16 @@ class RemoveModalForm(BaseModalForm):
|
||||
self.form_caption = _("Are you sure?")
|
||||
|
||||
def save(self):
|
||||
if hasattr(self.instance, "deleted"):
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=self.user,
|
||||
timestamp=timezone.now(),
|
||||
action=UserAction.DELETED,
|
||||
)
|
||||
self.instance.deleted = action
|
||||
self.instance.save()
|
||||
if isinstance(self.instance, BaseObject):
|
||||
with transaction.atomic():
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=self.user,
|
||||
timestamp=timezone.now(),
|
||||
action=UserAction.DELETED,
|
||||
)
|
||||
self.instance.deleted = action
|
||||
self.instance.log.add(action)
|
||||
self.instance.save()
|
||||
else:
|
||||
# If the class does not provide restorable delete functionality, we must delete the entry finally
|
||||
self.instance.delete()
|
||||
@@ -317,4 +319,12 @@ class NewDocumentForm(BaseModalForm):
|
||||
date_of_creation=self.cleaned_data["creation_date"],
|
||||
)
|
||||
self.instance.documents.add(doc)
|
||||
return doc
|
||||
|
||||
edited_action = UserActionLogEntry.objects.create(
|
||||
user=self.user,
|
||||
action=UserAction.EDITED,
|
||||
comment=_("Added document"),
|
||||
)
|
||||
self.instance.log.add(edited_action)
|
||||
|
||||
return doc
|
||||
|
||||
@@ -8,6 +8,7 @@ Created on: 17.11.20
|
||||
import os
|
||||
import uuid
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.contrib.gis.db.models import MultiPolygonField
|
||||
from django.db import models, transaction
|
||||
@@ -54,6 +55,7 @@ class BaseObject(BaseResource):
|
||||
title = models.CharField(max_length=1000, null=True, blank=True)
|
||||
deleted = models.ForeignKey(UserActionLogEntry, on_delete=models.SET_NULL, null=True, blank=True, related_name='+')
|
||||
comment = models.TextField(null=True, blank=True)
|
||||
log = models.ManyToManyField(UserActionLogEntry, blank=True, help_text="Keeps all user actions of an object", editable=False)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
@@ -83,6 +85,23 @@ class BaseObject(BaseResource):
|
||||
self.deleted = action
|
||||
self.save()
|
||||
|
||||
def add_log_entry(self, action: UserAction, user: User, comment: str):
|
||||
""" Wraps adding of UserActionLogEntry to self.log
|
||||
|
||||
Args:
|
||||
action (UserAction): The performed UserAction
|
||||
user (User): Performing user
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
user_action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=action,
|
||||
comment=comment
|
||||
)
|
||||
self.log.add(user_action)
|
||||
|
||||
|
||||
class DeadlineType(models.TextChoices):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user