From 69a4331d9954d34e76f7387ea8ba51fc58d20326 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon, 25 Nov 2024 20:39:51 -0800 Subject: [PATCH] setup placeholder vars once --- src/documents/signals/handlers.py | 64 +++++++++++++++++-------------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/src/documents/signals/handlers.py b/src/documents/signals/handlers.py index 96c956132..e3344a656 100644 --- a/src/documents/signals/handlers.py +++ b/src/documents/signals/handlers.py @@ -884,25 +884,31 @@ def run_workflows( doc_url = None if isinstance(document, Document): doc_url = f"{settings.PAPERLESS_URL}/documents/{document.pk}/" + correspondent = document.correspondent.name if document.correspondent else "" + document_type = document.document_type.name if document.document_type else "" + owner_username = document.owner.username if document.owner else "" + filename = document.original_filename or "" + added = timezone.localtime(document.added) + created = timezone.localtime(document.created) subject = parse_w_workflow_placeholders( action.email_subject, - document.correspondent.name if document.correspondent else "", - document.document_type.name if document.document_type else "", - document.owner.username if document.owner else "", - timezone.localtime(document.added), - document.original_filename or "", - timezone.localtime(document.created), + correspondent, + document_type, + owner_username, + added, + filename, + created, title, doc_url, ) body = parse_w_workflow_placeholders( action.email_body, - document.correspondent.name if document.correspondent else "", - document.document_type.name if document.document_type else "", - document.owner.username if document.owner else "", - timezone.localtime(document.added), - document.original_filename or "", - timezone.localtime(document.created), + correspondent, + document_type, + owner_username, + added, + filename, + created, title, doc_url, ) @@ -934,6 +940,12 @@ def run_workflows( doc_url = None if isinstance(document, Document): doc_url = f"{settings.PAPERLESS_URL}/documents/{document.pk}/" + correspondent = document.correspondent.name if document.correspondent else "" + document_type = document.document_type.name if document.document_type else "" + owner_username = document.owner.username if document.owner else "" + filename = document.original_filename or "" + added = timezone.localtime(document.added) + created = timezone.localtime(document.created) try: data = {} @@ -942,16 +954,12 @@ def run_workflows( for key, value in action.webhook_params.items(): data[key] = parse_w_workflow_placeholders( value, - document.correspondent.name - if document.correspondent - else "", - document.document_type.name - if document.document_type - else "", - document.owner.username if document.owner else "", - timezone.localtime(document.added), - document.original_filename or "", - timezone.localtime(document.created), + correspondent, + document_type, + owner_username, + added, + filename, + created, title, doc_url, ) @@ -963,12 +971,12 @@ def run_workflows( else: data = parse_w_workflow_placeholders( action.webhook_body, - document.correspondent.name if document.correspondent else "", - document.document_type.name if document.document_type else "", - document.owner.username if document.owner else "", - timezone.localtime(document.added), - document.original_filename or "", - timezone.localtime(document.created), + correspondent, + document_type, + owner_username, + added, + filename, + created, title, doc_url, )