Files
mayan-edms/mayan/apps/ocr/utils.py
Roberto Rosario 26f6152356 Add "ocr_content" accessor to the DocumentVersion class to return
the ocr content.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
2017-08-25 02:07:58 -04:00

20 lines
568 B
Python

from __future__ import unicode_literals
from django.apps import apps
from django.utils.encoding import force_text
from django.utils.html import conditional_escape
def get_document_ocr_content(document):
DocumentPageOCRContent = apps.get_model(
app_label='ocr', model_name='DocumentPageOCRContent'
)
for page in document.pages.all():
try:
page_content = page.ocr_content.content
except DocumentPageOCRContent.DoesNotExist:
pass
else:
yield conditional_escape(force_text(page_content))