mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-10-24 08:38:55 +00:00
Backend work for proper bulk zone ocr
This commit is contained in:
8 files changed
+179
No files matched your search
@@ -38,6 +38,7 @@ from documents.permissions import set_permissions_for_objects
|
||||
from documents.plugins.helpers import DocumentsStatusManager
|
||||
from documents.tasks import bulk_update_documents
|
||||
from documents.tasks import consume_file
|
||||
from documents.tasks import extract_zones
|
||||
from documents.tasks import remove_document_from_index
|
||||
from documents.tasks import update_document_content_maybe_archive_file
|
||||
from documents.versioning import get_latest_version_for_root
|
||||
@@ -1231,3 +1232,26 @@ def remove_doclink(
|
||||
target_doc_field_instance.value.remove(document.id)
|
||||
target_doc_field_instance.save()
|
||||
Document.objects.filter(id=target_doc_id).update(modified=timezone.now())
|
||||
|
||||
|
||||
def run_zone_ocr(doc_ids: list[int]) -> Literal["OK"]:
|
||||
"""
|
||||
Queue zone OCR for the given documents. Documents whose type has no enabled
|
||||
OCR template are skipped.
|
||||
"""
|
||||
document_ids = (
|
||||
Document.objects.filter(
|
||||
id__in=doc_ids,
|
||||
document_type__ocr_templates__enabled=True,
|
||||
)
|
||||
.order_by()
|
||||
.values_list("id", flat=True)
|
||||
.distinct()
|
||||
)
|
||||
for document_id in document_ids:
|
||||
extract_zones.apply_async(
|
||||
kwargs={"document_id": document_id},
|
||||
headers={"trigger_source": PaperlessTask.TriggerSource.MANUAL},
|
||||
)
|
||||
|
||||
return "OK"
|
||||
Reference in new issue
Block a user