Refactors triggering checked/recorded
* refactors BaseForm request/user initialization * introduces mark_as_edited() method for compensation models
This commit is contained in:
@@ -8,9 +8,10 @@ Created on: 15.11.21
|
||||
|
||||
import uuid
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.utils import timezone
|
||||
from django.http import HttpRequest
|
||||
from django.utils.timezone import now
|
||||
from django.db import models, transaction
|
||||
from compensation.settings import COMPENSATION_IDENTIFIER_TEMPLATE, COMPENSATION_IDENTIFIER_LENGTH, \
|
||||
@@ -19,6 +20,7 @@ from ema.settings import EMA_ACCOUNT_IDENTIFIER_LENGTH, EMA_ACCOUNT_IDENTIFIER_T
|
||||
from intervention.settings import INTERVENTION_IDENTIFIER_LENGTH, INTERVENTION_IDENTIFIER_TEMPLATE
|
||||
from konova.utils import generators
|
||||
from konova.utils.generators import generate_random_string
|
||||
from konova.utils.message_templates import CHECKED_RECORDED_RESET
|
||||
from user.models import UserActionLogEntry, UserAction
|
||||
|
||||
|
||||
@@ -228,7 +230,7 @@ class RecordableObjectMixin(models.Model):
|
||||
self.log.add(action)
|
||||
return action
|
||||
|
||||
def mark_as_edited(self, performing_user: User):
|
||||
def mark_as_edited(self, performing_user: User, request: HttpRequest = None, edit_comment: str = None):
|
||||
""" In case the object or a related object changed, internal processes need to be started, such as
|
||||
unrecord and uncheck
|
||||
|
||||
@@ -238,9 +240,18 @@ class RecordableObjectMixin(models.Model):
|
||||
Returns:
|
||||
|
||||
"""
|
||||
action = UserActionLogEntry.get_edited_action(performing_user, edit_comment)
|
||||
self.modified = action
|
||||
self.log.add(action)
|
||||
self.save()
|
||||
|
||||
if self.recorded:
|
||||
self.set_unrecorded(performing_user)
|
||||
if request:
|
||||
messages.info(
|
||||
request,
|
||||
CHECKED_RECORDED_RESET
|
||||
)
|
||||
|
||||
|
||||
class CheckableObjectMixin(models.Model):
|
||||
|
||||
Reference in New Issue
Block a user