Refactor the model accesors
Refactor the accesors to behave like methods instead of properties. This means all accesors will be prepended with the string "get_" and will include a set of parenthesis. Improve the ModeAttribute class to use the method's short_description. This commit also adds support for a new method .help_text attribute has been added. Move accessors to their own module, named "methods.py". Remove the PropertyHelper class as the accessors no longer need it. Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
@@ -4,20 +4,24 @@ from django.apps import apps
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
|
||||
def get_document_ocr_content(document):
|
||||
def get_document_content_iterator(document):
|
||||
latest_version = document.latest_version
|
||||
|
||||
if latest_version:
|
||||
return get_document_version_content_iterator(
|
||||
document_version=latest_version
|
||||
)
|
||||
|
||||
|
||||
def get_document_version_content_iterator(document_version):
|
||||
DocumentPageOCRContent = apps.get_model(
|
||||
app_label='ocr', model_name='DocumentPageOCRContent'
|
||||
)
|
||||
|
||||
for page in document.pages.all():
|
||||
for page in document_version.pages.all():
|
||||
try:
|
||||
page_content = page.ocr_content.content
|
||||
except DocumentPageOCRContent.DoesNotExist:
|
||||
return
|
||||
else:
|
||||
yield force_text(page_content)
|
||||
|
||||
|
||||
@property
|
||||
def document_property_ocr_content(self):
|
||||
return ' '.join(get_document_ocr_content(self))
|
||||
|
||||
Reference in New Issue
Block a user