From 7e4bd3591d136e7d7020eabed7891324cfa326ff Mon Sep 17 00:00:00 2001 From: Felix Rindt Date: Wed, 28 Jun 2023 17:24:18 +0200 Subject: [PATCH] refactor logentry config save hook --- ephios/modellogging/log.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ephios/modellogging/log.py b/ephios/modellogging/log.py index 9faeffca6..c2839ca99 100644 --- a/ephios/modellogging/log.py +++ b/ephios/modellogging/log.py @@ -1,4 +1,3 @@ -import contextlib import itertools import threading from typing import Dict @@ -16,8 +15,6 @@ class BaseLogConfig: - log_entry_context_manager = contextlib.nullcontext - def initial_log_recorders(self, instance): """ Initial log recorders are always added after model __init__. @@ -45,6 +42,13 @@ def object_to_attach_logentries_to(self, instance): """ return type(instance), instance.pk + def save_logentry(self, logentry: LogEntry): + """ + Save the logentry. Overwrite this method to process the logentry + bevore saving. + """ + logentry.save() + class ModelFieldsLogConfig(BaseLogConfig): def __init__(self, unlogged_fields=None, attach_to_func=None, initial_recorders_func=None): @@ -156,8 +160,7 @@ def update_log(instance, action_type: InstanceActionType): data=log_data, ) - with config.log_entry_context_manager(): - logentry.save() + config.save_logentry(logentry) instance._current_logentry = logentry