mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-09 09:58:20 -05:00
Add document name & error result parsing to PaperlessTask serializer
This commit is contained in:
parent
c289439cab
commit
c8f252d165
@ -1,5 +1,7 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
import json
|
||||||
import math
|
import math
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -630,6 +632,7 @@ class TasksViewSerializer(serializers.ModelSerializer):
|
|||||||
"result",
|
"result",
|
||||||
"acknowledged",
|
"acknowledged",
|
||||||
"task_name",
|
"task_name",
|
||||||
|
"name",
|
||||||
)
|
)
|
||||||
|
|
||||||
type = serializers.SerializerMethodField()
|
type = serializers.SerializerMethodField()
|
||||||
@ -643,7 +646,15 @@ class TasksViewSerializer(serializers.ModelSerializer):
|
|||||||
def get_result(self, obj):
|
def get_result(self, obj):
|
||||||
result = ""
|
result = ""
|
||||||
if hasattr(obj, "attempted_task") and obj.attempted_task:
|
if hasattr(obj, "attempted_task") and obj.attempted_task:
|
||||||
result = obj.attempted_task.result
|
try:
|
||||||
|
result_json = json.loads(obj.attempted_task.result)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if result_json and "exc_message" in result_json:
|
||||||
|
result = result_json["exc_message"]
|
||||||
|
else:
|
||||||
|
result = obj.attempted_task.result.strip('"')
|
||||||
return result
|
return result
|
||||||
|
|
||||||
status = serializers.SerializerMethodField()
|
status = serializers.SerializerMethodField()
|
||||||
@ -686,6 +697,35 @@ class TasksViewSerializer(serializers.ModelSerializer):
|
|||||||
result = obj.attempted_task.task_name
|
result = obj.attempted_task.task_name
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
name = serializers.SerializerMethodField()
|
||||||
|
|
||||||
|
def get_name(self, obj):
|
||||||
|
result = ""
|
||||||
|
if hasattr(obj, "attempted_task") and obj.attempted_task:
|
||||||
|
try:
|
||||||
|
# We have to make this a valid JSON object string
|
||||||
|
kwargs_json = json.loads(
|
||||||
|
obj.attempted_task.task_kwargs.strip('"')
|
||||||
|
.replace("'", '"')
|
||||||
|
.replace("None", '""'),
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if kwargs_json and "override_filename" in kwargs_json:
|
||||||
|
result = kwargs_json["override_filename"]
|
||||||
|
else:
|
||||||
|
filepath = (
|
||||||
|
obj.attempted_task.task_args.replace('"', "")
|
||||||
|
.replace("'", "")
|
||||||
|
.replace("(", "")
|
||||||
|
.replace(")", "")
|
||||||
|
.replace(",", "")
|
||||||
|
)
|
||||||
|
result = os.path.split(filepath)[1]
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
class AcknowledgeTasksViewSerializer(serializers.Serializer):
|
class AcknowledgeTasksViewSerializer(serializers.Serializer):
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user