mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-29 16:23:18 +00:00
Chore: type zone OCR results and reasons
Reasons become a StrEnum, the run response has a serializer instead of an untyped dict list, and the zone preview returns its dataclass. The JSON is unchanged.
This commit is contained in:
1 parent
4c2df48795
commit
a490d9d348
5 files changed
+164
-60
No files matched your search
@@ -98,6 +98,7 @@ from documents.validators import uri_validator
|
||||
from documents.validators import url_validator
|
||||
from documents.versioning import has_prefetched_effective_content
|
||||
from documents.versioning import sort_versions_newest_first
|
||||
from documents.zone_ocr import ZoneOcrReason
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Iterable
|
||||
@@ -1826,6 +1827,28 @@ class RunZoneOcrSerializer(serializers.Serializer):
|
||||
).prefetch_related("zones", "zones__custom_field")
|
||||
|
||||
|
||||
class ZoneOcrResultSerializer(serializers.Serializer):
|
||||
"""The outcome of one zone, mirroring the ZoneOcrResult dataclass."""
|
||||
|
||||
template = serializers.CharField(read_only=True)
|
||||
zone = serializers.CharField(read_only=True)
|
||||
custom_field = serializers.CharField(read_only=True)
|
||||
value = serializers.JSONField(
|
||||
read_only=True,
|
||||
allow_null=True,
|
||||
help_text=(
|
||||
"The value written to the target. A string, number, boolean or ISO "
|
||||
"date string, depending on the target, or null when nothing was written."
|
||||
),
|
||||
)
|
||||
reason = serializers.ChoiceField(
|
||||
choices=[reason.value for reason in ZoneOcrReason],
|
||||
read_only=True,
|
||||
allow_null=True,
|
||||
help_text="Why no value was written, or null when one was.",
|
||||
)
|
||||
|
||||
|
||||
class RunZoneOcrDocumentsSerializer(DocumentSelectionSerializer, RunZoneOcrSerializer):
|
||||
from_webui = serializers.BooleanField(required=False, default=False)
|
||||
|
||||
|
||||
Reference in new issue
Block a user