Fix return messages thing
This commit is contained in:
parent
780c9f1114
commit
4ab080166c
@ -59,10 +59,9 @@ class WorkflowTriggerPlugin(
|
|||||||
|
|
||||||
def run(self) -> str | None:
|
def run(self) -> str | None:
|
||||||
"""
|
"""
|
||||||
Get overrides from matching workflows
|
Run matching workflows
|
||||||
"""
|
"""
|
||||||
msg = ""
|
overrides, msg = run_workflows(
|
||||||
overrides = run_workflows(
|
|
||||||
WorkflowTrigger.WorkflowTriggerType.CONSUMPTION,
|
WorkflowTrigger.WorkflowTriggerType.CONSUMPTION,
|
||||||
self.input_doc,
|
self.input_doc,
|
||||||
"paperless_consumer",
|
"paperless_consumer",
|
||||||
|
@ -534,7 +534,7 @@ def run_workflows(
|
|||||||
document: Document | ConsumableDocument,
|
document: Document | ConsumableDocument,
|
||||||
logging_group=None,
|
logging_group=None,
|
||||||
overrides: DocumentMetadataOverrides | None = None,
|
overrides: DocumentMetadataOverrides | None = None,
|
||||||
):
|
) -> tuple[DocumentMetadataOverrides, str] | None:
|
||||||
def assignment_action():
|
def assignment_action():
|
||||||
if action.assign_tags.all().count() > 0:
|
if action.assign_tags.all().count() > 0:
|
||||||
if not use_overrides:
|
if not use_overrides:
|
||||||
@ -597,10 +597,14 @@ def run_workflows(
|
|||||||
timezone.localtime(document.created),
|
timezone.localtime(document.created),
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
message = f"Error occurred parsing title assignment '{action.assign_title}', falling back to original"
|
||||||
|
if not use_overrides:
|
||||||
logger.exception(
|
logger.exception(
|
||||||
f"Error occurred parsing title assignment '{action.assign_title}', falling back to original",
|
message,
|
||||||
extra={"group": logging_group},
|
extra={"group": logging_group},
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
messages.append(message)
|
||||||
else:
|
else:
|
||||||
overrides.title = action.assign_title
|
overrides.title = action.assign_title
|
||||||
|
|
||||||
@ -867,6 +871,7 @@ def run_workflows(
|
|||||||
overrides.custom_field_ids.remove(field.pk)
|
overrides.custom_field_ids.remove(field.pk)
|
||||||
|
|
||||||
use_overrides = overrides is not None
|
use_overrides = overrides is not None
|
||||||
|
messages = []
|
||||||
|
|
||||||
for workflow in (
|
for workflow in (
|
||||||
Workflow.objects.filter(
|
Workflow.objects.filter(
|
||||||
@ -903,10 +908,14 @@ def run_workflows(
|
|||||||
):
|
):
|
||||||
action: WorkflowAction
|
action: WorkflowAction
|
||||||
for action in workflow.actions.all():
|
for action in workflow.actions.all():
|
||||||
|
message = f"Applying {action} from {workflow}"
|
||||||
|
if not use_overrides:
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Applying {action} from {workflow}",
|
message,
|
||||||
extra={"group": logging_group},
|
extra={"group": logging_group},
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
messages.append(message)
|
||||||
|
|
||||||
if action.type == WorkflowAction.WorkflowActionType.ASSIGNMENT:
|
if action.type == WorkflowAction.WorkflowActionType.ASSIGNMENT:
|
||||||
assignment_action()
|
assignment_action()
|
||||||
@ -918,8 +927,8 @@ def run_workflows(
|
|||||||
# save first before setting tags
|
# save first before setting tags
|
||||||
document.save()
|
document.save()
|
||||||
document.tags.set(doc_tag_ids)
|
document.tags.set(doc_tag_ids)
|
||||||
else:
|
if use_overrides:
|
||||||
return overrides
|
return overrides, "\n".join(messages)
|
||||||
|
|
||||||
|
|
||||||
@before_task_publish.connect
|
@before_task_publish.connect
|
||||||
|
Loading…
x
Reference in New Issue
Block a user