From c28b636ffaecc30e44cb231d39de8c2f1ed6d545 Mon Sep 17 00:00:00 2001 From: Jonas Winkler Date: Mon, 2 Nov 2020 19:27:24 +0100 Subject: [PATCH] fixed unnecessary assignation of correspondents / types to documents --- src/documents/signals/handlers.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/documents/signals/handlers.py b/src/documents/signals/handlers.py index 8c893e46c..def1d5a5f 100755 --- a/src/documents/signals/handlers.py +++ b/src/documents/signals/handlers.py @@ -51,14 +51,14 @@ def set_correspondent(sender, document=None, logging_group=None, classifier=None ) return - logger( - 'Assigning correspondent "{}" to "{}" '.format(selected, document), - logging_group - ) - # TODO: during consumption, this saves even though no updates have been made + if selected or replace: + logger( + 'Assigning correspondent "{}" to "{}" '.format(selected, document), + logging_group + ) - document.correspondent = selected - document.save(update_fields=("correspondent",)) + document.correspondent = selected + document.save(update_fields=("correspondent",)) def set_document_type(sender, document=None, logging_group=None, classifier=None, replace=False, use_first=True, **kwargs): @@ -88,13 +88,14 @@ def set_document_type(sender, document=None, logging_group=None, classifier=None ) return - logger( - 'Assigning document type "{}" to "{}" '.format(selected, document), - logging_group - ) + if selected or replace: + logger( + 'Assigning document type "{}" to "{}" '.format(selected, document), + logging_group + ) - document.document_type = selected - document.save(update_fields=("document_type",)) + document.document_type = selected + document.save(update_fields=("document_type",)) def set_tags(sender, document=None, logging_group=None, classifier=None, replace=False, **kwargs):