Documents now have their own dedicated DocumentPage submodel. The old DocumentPage is now called DocumentVersionPage. This allows mappings between document pages and document version pages, allowing renumbering, appending pages. DocumentPages have a content_object to map them to any other object. For now they only map to DocumentVersionPages. New option added to the version upload form to append the pages of the new version. A new view was added to just append new pages with wraps the new document version upload form and hides the append pages checkbox set to True. Add a new action, reset_pages to reset the pages of the document to those of the latest version. Missing: appending tests, checks for proper content_object in OCR and document parsing. Author: Roberto Rosario <roberto.rosario@mayan-edms.com> Date: Thu Oct 11 12:00:25 2019 -0400
33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
from __future__ import unicode_literals
|
|
|
|
from django.apps import apps
|
|
from django.utils.encoding import force_text
|
|
|
|
|
|
def get_document_version_ocr_content(document_version):
|
|
DocumentVersionPageOCRContent = apps.get_model(
|
|
app_label='ocr', model_name='DocumentVersionPageOCRContent'
|
|
)
|
|
|
|
for document_version_page in document_version.pages.all():
|
|
try:
|
|
page_content = document_version_page.ocr_content.content
|
|
except DocumentVersionPageOCRContent.DoesNotExist:
|
|
pass
|
|
else:
|
|
yield force_text(page_content)
|
|
|
|
|
|
def get_document_ocr_content(document):
|
|
DocumentVersionPageOCRContent = apps.get_model(
|
|
app_label='ocr', model_name='DocumentVersionPageOCRContent'
|
|
)
|
|
|
|
for document_page in document.pages.all():
|
|
try:
|
|
page_content = document_page.content_object.ocr_content.content
|
|
except (AttributeError, DocumentVersionPageOCRContent.DoesNotExist):
|
|
pass
|
|
else:
|
|
yield force_text(page_content)
|