mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-07-10 05:55:09 +00:00
Compare commits
1 Commits
feature/angular22
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| f244442c65 |
@@ -1847,6 +1847,45 @@ class TestWorkflows(
|
|||||||
|
|
||||||
self.assertEqual(doc.title, "Doc {created_year]")
|
self.assertEqual(doc.title, "Doc {created_year]")
|
||||||
|
|
||||||
|
def test_document_added_malformed_title_template_falls_back(self) -> None:
|
||||||
|
"""
|
||||||
|
GIVEN:
|
||||||
|
- Existing workflow with added trigger type
|
||||||
|
- Assign title field is malformed Jinja2 syntax
|
||||||
|
WHEN:
|
||||||
|
- File that matches is added
|
||||||
|
THEN:
|
||||||
|
- Title assignment is skipped and the original title is kept
|
||||||
|
"""
|
||||||
|
trigger = WorkflowTrigger.objects.create(
|
||||||
|
type=WorkflowTrigger.WorkflowTriggerType.DOCUMENT_ADDED,
|
||||||
|
filter_filename="*sample*",
|
||||||
|
)
|
||||||
|
action = WorkflowAction.objects.create(
|
||||||
|
assign_title="Doc {{ unclosed",
|
||||||
|
)
|
||||||
|
w = Workflow.objects.create(
|
||||||
|
name="Workflow 1",
|
||||||
|
order=0,
|
||||||
|
)
|
||||||
|
w.triggers.add(trigger)
|
||||||
|
w.actions.add(action)
|
||||||
|
w.save()
|
||||||
|
|
||||||
|
doc = Document.objects.create(
|
||||||
|
original_filename="sample.pdf",
|
||||||
|
title="sample test",
|
||||||
|
content="Hello world bar",
|
||||||
|
)
|
||||||
|
|
||||||
|
document_consumption_finished.send(
|
||||||
|
sender=self.__class__,
|
||||||
|
document=doc,
|
||||||
|
)
|
||||||
|
|
||||||
|
doc.refresh_from_db()
|
||||||
|
self.assertEqual(doc.title, "sample test")
|
||||||
|
|
||||||
def test_document_updated_workflow_ignores_version_documents(self) -> None:
|
def test_document_updated_workflow_ignores_version_documents(self) -> None:
|
||||||
trigger = WorkflowTrigger.objects.create(
|
trigger = WorkflowTrigger.objects.create(
|
||||||
type=WorkflowTrigger.WorkflowTriggerType.DOCUMENT_UPDATED,
|
type=WorkflowTrigger.WorkflowTriggerType.DOCUMENT_UPDATED,
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ def apply_assignment_to_document(
|
|||||||
|
|
||||||
if action.assign_title:
|
if action.assign_title:
|
||||||
try:
|
try:
|
||||||
document.title = parse_w_workflow_placeholders(
|
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 "",
|
||||||
@@ -53,6 +53,8 @@ def apply_assignment_to_document(
|
|||||||
"", # no urls in titles
|
"", # no urls in titles
|
||||||
document.pk,
|
document.pk,
|
||||||
)
|
)
|
||||||
|
if title:
|
||||||
|
document.title = title
|
||||||
except Exception: # pragma: no cover
|
except Exception: # pragma: no cover
|
||||||
logger.exception(
|
logger.exception(
|
||||||
f"Error occurred parsing title assignment '{action.assign_title}', falling back to original",
|
f"Error occurred parsing title assignment '{action.assign_title}', falling back to original",
|
||||||
|
|||||||
Reference in New Issue
Block a user