Files
mayan-edms/mayan/apps/document_parsing/utils.py
Roberto Rosario 5a626861ae Parsing: Add the 'content' attribute
Add the 'content' attribute to documents to allow access
to a document's parsed content for indexing and other purposes.

Fixes the document parsing indexing failing test.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
2018-11-27 05:24:55 -04:00

25 lines
665 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_content(document):
DocumentPageContent = apps.get_model(
app_label='document_parsing', model_name='DocumentPageContent'
)
for page in document.pages.all():
try:
page_content = page.content.content
except DocumentPageContent.DoesNotExist:
yield ''
else:
yield conditional_escape(force_text(page_content))
@property
def document_property_content(self):
return ' '.join(get_document_content(self))