]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Enhancement: include current filename placeholder in workflows (#8319)
authorlufi <lutz@fiebach.de>
Tue, 3 Dec 2024 03:09:27 +0000 (04:09 +0100)
committerGitHub <noreply@github.com>
Tue, 3 Dec 2024 03:09:27 +0000 (03:09 +0000)
Co-authored-by: Trenton H <797416+stumpylog@users.noreply.github.com>
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
docs/usage.md
src/documents/consumer.py
src/documents/serialisers.py
src/documents/signals/handlers.py
src/documents/templating/workflows.py

index 0979c859f67b0c91137ee5389c4eba3756ee6b79..cf4970e3c90e30bd236abe3c5d72236f4ecb1ad2 100644 (file)
@@ -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
 
index 81a4be32bb313ed888527dda9268255467369155..f353afbe744949074c1516694a20f5eee44cbe6e 100644 (file)
@@ -673,6 +673,7 @@ class ConsumerPlugin(
             owner_username,
             local_added,
             self.filename,
+            self.filename,
         )
 
     def _store(
index 937e293d080feb5e8b707131808f36f24f471959..d431d067383a351f8e40a859e81787d2335d639a 100644 (file)
@@ -1917,6 +1917,7 @@ class WorkflowActionSerializer(serializers.ModelSerializer):
                         added_time="",
                         owner_username="",
                         original_filename="",
+                        filename="",
                         created="",
                         created_year="",
                         created_year_short="",
index 0e5a577435a49afed8ac689ac9a425531653658a..d669e3a0f3df2a403c266970149244472f11fee4 100644 (file)
@@ -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,
index 1eea47dc3e212d72fb4ffee66b52a46c034718c3..e256e303098689b41072d62b6854f5b334a7a0a2 100644 (file)
@@ -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(