mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-22 17:54:40 -05:00

Co-authored-by: Trenton H <797416+stumpylog@users.noreply.github.com> Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
55 lines
2.0 KiB
Python
55 lines
2.0 KiB
Python
from datetime import datetime
|
|
from pathlib import Path
|
|
|
|
|
|
def parse_w_workflow_placeholders(
|
|
text: str,
|
|
correspondent_name: str,
|
|
doc_type_name: str,
|
|
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,
|
|
) -> 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,
|
|
"filename": Path(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"),
|
|
},
|
|
)
|
|
if doc_title is not None:
|
|
formatting.update({"doc_title": doc_title})
|
|
if doc_url is not None:
|
|
formatting.update({"doc_url": doc_url})
|
|
return text.format(**formatting).strip()
|