From 0406fca59bf7c29cb3e70577f639d64252400767 Mon Sep 17 00:00:00 2001 From: lufi Date: Tue, 3 Dec 2024 04:09:27 +0100 Subject: [PATCH] Enhancement: include current filename placeholder in workflows (#8319) Co-authored-by: Trenton H <797416+stumpylog@users.noreply.github.com> Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com> --- docs/usage.md | 1 + src/documents/consumer.py | 1 + src/documents/serialisers.py | 1 + src/documents/signals/handlers.py | 7 +++++++ src/documents/templating/workflows.py | 2 ++ 5 files changed, 12 insertions(+) diff --git a/docs/usage.md b/docs/usage.md index 0979c859f..cf4970e3c 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -439,6 +439,7 @@ applied. You can use the following placeholders with any trigger type: - `{added_day}`: added day - `{added_time}`: added time in HH:MM format - `{original_filename}`: original file name without extension +- `{filename}`: current file name without extension The following placeholders are only available for "added" or "updated" triggers diff --git a/src/documents/consumer.py b/src/documents/consumer.py index 81a4be32b..f353afbe7 100644 --- a/src/documents/consumer.py +++ b/src/documents/consumer.py @@ -673,6 +673,7 @@ class ConsumerPlugin( owner_username, local_added, self.filename, + self.filename, ) def _store( diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index 937e293d0..d431d0673 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -1917,6 +1917,7 @@ class WorkflowActionSerializer(serializers.ModelSerializer): added_time="", owner_username="", original_filename="", + filename="", created="", created_year="", created_year_short="", diff --git a/src/documents/signals/handlers.py b/src/documents/signals/handlers.py index 0e5a57743..d669e3a0f 100644 --- a/src/documents/signals/handlers.py +++ b/src/documents/signals/handlers.py @@ -656,6 +656,7 @@ def run_workflows( document.owner.username if document.owner else "", timezone.localtime(document.added), document.original_filename or "", + document.filename or "", timezone.localtime(document.created), ) except Exception: @@ -926,6 +927,7 @@ def run_workflows( 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 "" + current_filename = document.filename or "" added = timezone.localtime(document.added) created = timezone.localtime(document.created) subject = parse_w_workflow_placeholders( @@ -935,6 +937,7 @@ def run_workflows( owner_username, added, filename, + current_filename, created, title, doc_url, @@ -946,6 +949,7 @@ def run_workflows( owner_username, added, filename, + current_filename, created, title, doc_url, @@ -982,6 +986,7 @@ def run_workflows( 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 "" + current_filename = document.filename or "" added = timezone.localtime(document.added) created = timezone.localtime(document.created) @@ -997,6 +1002,7 @@ def run_workflows( owner_username, added, filename, + current_filename, created, title, doc_url, @@ -1014,6 +1020,7 @@ def run_workflows( owner_username, added, filename, + current_filename, created, title, doc_url, diff --git a/src/documents/templating/workflows.py b/src/documents/templating/workflows.py index 1eea47dc3..e256e3030 100644 --- a/src/documents/templating/workflows.py +++ b/src/documents/templating/workflows.py @@ -9,6 +9,7 @@ def parse_w_workflow_placeholders( owner_username: str, local_added: datetime, original_filename: str, + filename: str, created: datetime | None = None, doc_title: str | None = None, doc_url: str | None = None, @@ -31,6 +32,7 @@ def parse_w_workflow_placeholders( "added_time": local_added.strftime("%H:%M"), "owner_username": owner_username, "original_filename": Path(original_filename).stem, + "filename": Path(filename).stem, } if created is not None: formatting.update(