mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-05-01 11:19:32 -05:00
Basic templating
This commit is contained in:
parent
892b7793da
commit
e9e19235aa
@ -43,7 +43,7 @@ from documents.plugins.helpers import ProgressStatusOptions
|
|||||||
from documents.signals import document_consumption_finished
|
from documents.signals import document_consumption_finished
|
||||||
from documents.signals import document_consumption_started
|
from documents.signals import document_consumption_started
|
||||||
from documents.signals.handlers import run_workflows
|
from documents.signals.handlers import run_workflows
|
||||||
from documents.templating.title import parse_doc_title_w_placeholders
|
from documents.templating.workflows import parse_w_workflow_placeholders
|
||||||
from documents.utils import copy_basic_file_stats
|
from documents.utils import copy_basic_file_stats
|
||||||
from documents.utils import copy_file_with_basic_stats
|
from documents.utils import copy_file_with_basic_stats
|
||||||
from documents.utils import run_subprocess
|
from documents.utils import run_subprocess
|
||||||
@ -666,7 +666,7 @@ class ConsumerPlugin(
|
|||||||
else None
|
else None
|
||||||
)
|
)
|
||||||
|
|
||||||
return parse_doc_title_w_placeholders(
|
return parse_w_workflow_placeholders(
|
||||||
title,
|
title,
|
||||||
correspondent_name,
|
correspondent_name,
|
||||||
doc_type_name,
|
doc_type_name,
|
||||||
|
@ -44,7 +44,7 @@ from documents.models import WorkflowRun
|
|||||||
from documents.models import WorkflowTrigger
|
from documents.models import WorkflowTrigger
|
||||||
from documents.permissions import get_objects_for_user_owner_aware
|
from documents.permissions import get_objects_for_user_owner_aware
|
||||||
from documents.permissions import set_permissions_for_object
|
from documents.permissions import set_permissions_for_object
|
||||||
from documents.templating.title import parse_doc_title_w_placeholders
|
from documents.templating.workflows import parse_w_workflow_placeholders
|
||||||
|
|
||||||
logger = logging.getLogger("paperless.handlers")
|
logger = logging.getLogger("paperless.handlers")
|
||||||
|
|
||||||
@ -612,7 +612,7 @@ def run_workflows(
|
|||||||
if action.assign_title:
|
if action.assign_title:
|
||||||
if not use_overrides:
|
if not use_overrides:
|
||||||
try:
|
try:
|
||||||
document.title = parse_doc_title_w_placeholders(
|
document.title = parse_w_workflow_placeholders(
|
||||||
action.assign_title,
|
action.assign_title,
|
||||||
document.correspondent.name if document.correspondent else "",
|
document.correspondent.name if document.correspondent else "",
|
||||||
document.document_type.name if document.document_type else "",
|
document.document_type.name if document.document_type else "",
|
||||||
@ -870,7 +870,16 @@ def run_workflows(
|
|||||||
overrides.custom_field_ids.remove(field.pk)
|
overrides.custom_field_ids.remove(field.pk)
|
||||||
|
|
||||||
def notification_action():
|
def notification_action():
|
||||||
subject = parse_doc_title_w_placeholders(
|
title = (
|
||||||
|
document.title
|
||||||
|
if isinstance(document, Document)
|
||||||
|
else str(document.original_file)
|
||||||
|
)
|
||||||
|
doc_url = None
|
||||||
|
if isinstance(document, Document):
|
||||||
|
doc_url = f"{settings.PAPERLESS_URL}/documents/{document.pk}/"
|
||||||
|
|
||||||
|
subject = parse_w_workflow_placeholders(
|
||||||
action.notification_subject,
|
action.notification_subject,
|
||||||
document.correspondent.name if document.correspondent else "",
|
document.correspondent.name if document.correspondent else "",
|
||||||
document.document_type.name if document.document_type else "",
|
document.document_type.name if document.document_type else "",
|
||||||
@ -878,16 +887,21 @@ def run_workflows(
|
|||||||
timezone.localtime(document.added),
|
timezone.localtime(document.added),
|
||||||
document.original_filename or "",
|
document.original_filename or "",
|
||||||
timezone.localtime(document.created),
|
timezone.localtime(document.created),
|
||||||
|
title,
|
||||||
|
doc_url,
|
||||||
)
|
)
|
||||||
body = action.notification_body.format(
|
body = parse_w_workflow_placeholders(
|
||||||
title=subject,
|
action.notification_body,
|
||||||
document=document,
|
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),
|
||||||
|
title,
|
||||||
|
doc_url,
|
||||||
)
|
)
|
||||||
doc_url = None
|
|
||||||
if isinstance(document, Document):
|
|
||||||
doc_url = f"{settings.PAPERLESS_URL}/documents/{document.pk}/"
|
|
||||||
if doc_url:
|
|
||||||
body += f"\n\n{doc_url}"
|
|
||||||
if action.notification_destination_emails:
|
if action.notification_destination_emails:
|
||||||
if not settings.EMAIL_ENABLED:
|
if not settings.EMAIL_ENABLED:
|
||||||
logger.error(
|
logger.error(
|
||||||
|
@ -2,14 +2,16 @@ from datetime import datetime
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
def parse_doc_title_w_placeholders(
|
def parse_w_workflow_placeholders(
|
||||||
title: str,
|
text: str,
|
||||||
correspondent_name: str,
|
correspondent_name: str,
|
||||||
doc_type_name: str,
|
doc_type_name: str,
|
||||||
owner_username: str,
|
owner_username: str,
|
||||||
local_added: datetime,
|
local_added: datetime,
|
||||||
original_filename: str,
|
original_filename: str,
|
||||||
created: datetime | None = None,
|
created: datetime | None = None,
|
||||||
|
doc_title: str | None = None,
|
||||||
|
doc_url: str | None = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
"""
|
"""
|
||||||
Available title placeholders for Workflows depend on what has already been assigned,
|
Available title placeholders for Workflows depend on what has already been assigned,
|
||||||
@ -43,4 +45,8 @@ def parse_doc_title_w_placeholders(
|
|||||||
"created_time": created.strftime("%H:%M"),
|
"created_time": created.strftime("%H:%M"),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
return title.format(**formatting).strip()
|
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()
|
Loading…
x
Reference in New Issue
Block a user