diff --git a/src/documents/consumer.py b/src/documents/consumer.py index b86a27dc0..05e21671b 100644 --- a/src/documents/consumer.py +++ b/src/documents/consumer.py @@ -43,7 +43,7 @@ from documents.plugins.helpers import ProgressStatusOptions from documents.signals import document_consumption_finished from documents.signals import document_consumption_started from documents.signals.handlers import run_workflows -from documents.templating.filepath import parse_doc_title_w_placeholders +from documents.templating.title import parse_doc_title_w_placeholders from documents.utils import copy_basic_file_stats from documents.utils import copy_file_with_basic_stats from documents.utils import run_subprocess diff --git a/src/documents/signals/handlers.py b/src/documents/signals/handlers.py index 32c6aa6c7..f18cf1c9b 100644 --- a/src/documents/signals/handlers.py +++ b/src/documents/signals/handlers.py @@ -39,7 +39,7 @@ from documents.models import WorkflowAction from documents.models import WorkflowTrigger from documents.permissions import get_objects_for_user_owner_aware from documents.permissions import set_permissions_for_object -from documents.templating.filepath import parse_doc_title_w_placeholders +from documents.templating.title import parse_doc_title_w_placeholders logger = logging.getLogger("paperless.handlers") diff --git a/src/documents/templating/filepath.py b/src/documents/templating/filepath.py index ea31461fc..54ceb30a8 100644 --- a/src/documents/templating/filepath.py +++ b/src/documents/templating/filepath.py @@ -3,7 +3,6 @@ import os import re from collections.abc import Iterable from datetime import datetime -from pathlib import Path from pathlib import PurePath import pathvalidate @@ -331,47 +330,3 @@ def validate_filepath_template_and_render( f"Invalid filename_format '{template_string}', falling back to default", ) return None - - -def parse_doc_title_w_placeholders( - title: str, - correspondent_name: str, - doc_type_name: str, - owner_username: str, - local_added: datetime, - original_filename: str, - created: datetime | None = None, -) -> str: - """ - Available title placeholders for Workflows depend on what has already been assigned, - e.g. for pre-consumption triggers created will not have been parsed yet, but it will - for added / updated triggers - """ - formatting = { - "correspondent": correspondent_name, - "document_type": doc_type_name, - "added": local_added.isoformat(), - "added_year": local_added.strftime("%Y"), - "added_year_short": local_added.strftime("%y"), - "added_month": local_added.strftime("%m"), - "added_month_name": local_added.strftime("%B"), - "added_month_name_short": local_added.strftime("%b"), - "added_day": local_added.strftime("%d"), - "added_time": local_added.strftime("%H:%M"), - "owner_username": owner_username, - "original_filename": Path(original_filename).stem, - } - if created is not None: - formatting.update( - { - "created": created.isoformat(), - "created_year": created.strftime("%Y"), - "created_year_short": created.strftime("%y"), - "created_month": created.strftime("%m"), - "created_month_name": created.strftime("%B"), - "created_month_name_short": created.strftime("%b"), - "created_day": created.strftime("%d"), - "created_time": created.strftime("%H:%M"), - }, - ) - return title.format(**formatting).strip() diff --git a/src/documents/templating/title.py b/src/documents/templating/title.py new file mode 100644 index 000000000..1dc668c27 --- /dev/null +++ b/src/documents/templating/title.py @@ -0,0 +1,46 @@ +from datetime import datetime +from pathlib import Path + + +def parse_doc_title_w_placeholders( + title: str, + correspondent_name: str, + doc_type_name: str, + owner_username: str, + local_added: datetime, + original_filename: str, + created: datetime | None = None, +) -> str: + """ + Available title placeholders for Workflows depend on what has already been assigned, + e.g. for pre-consumption triggers created will not have been parsed yet, but it will + for added / updated triggers + """ + formatting = { + "correspondent": correspondent_name, + "document_type": doc_type_name, + "added": local_added.isoformat(), + "added_year": local_added.strftime("%Y"), + "added_year_short": local_added.strftime("%y"), + "added_month": local_added.strftime("%m"), + "added_month_name": local_added.strftime("%B"), + "added_month_name_short": local_added.strftime("%b"), + "added_day": local_added.strftime("%d"), + "added_time": local_added.strftime("%H:%M"), + "owner_username": owner_username, + "original_filename": Path(original_filename).stem, + } + if created is not None: + formatting.update( + { + "created": created.isoformat(), + "created_year": created.strftime("%Y"), + "created_year_short": created.strftime("%y"), + "created_month": created.strftime("%m"), + "created_month_name": created.strftime("%B"), + "created_month_name_short": created.strftime("%b"), + "created_day": created.strftime("%d"), + "created_time": created.strftime("%H:%M"), + }, + ) + return title.format(**formatting).strip()