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
82 lines
2.6 KiB
Python
82 lines
2.6 KiB
Python
from __future__ import unicode_literals
|
|
|
|
from django import forms
|
|
from django.utils.encoding import force_text
|
|
from django.utils.html import conditional_escape
|
|
from django.utils.safestring import mark_safe
|
|
from django.utils.translation import ugettext_lazy as _, ugettext
|
|
|
|
from mayan.apps.common.widgets import TextAreaDiv
|
|
|
|
from .models import DocumentVersionPageContent
|
|
|
|
|
|
class DocumentContentForm(forms.Form):
|
|
"""
|
|
Form that concatenates all of a document pages' text content into a
|
|
single textarea widget
|
|
"""
|
|
def __init__(self, *args, **kwargs):
|
|
self.document = kwargs.pop('instance', None)
|
|
super(DocumentContentForm, self).__init__(*args, **kwargs)
|
|
content = []
|
|
self.fields['contents'].initial = ''
|
|
try:
|
|
document_pages = self.document.pages.all()
|
|
except AttributeError:
|
|
document_pages = []
|
|
|
|
for document_page in document_pages:
|
|
try:
|
|
page_content = document_page.content_object.content.content
|
|
except DocumentVersionPageContent.DoesNotExist:
|
|
pass
|
|
else:
|
|
content.append(conditional_escape(force_text(page_content)))
|
|
content.append(
|
|
'\n\n\n<hr/><div class="document-page-content-divider">- %s -</div><hr/>\n\n\n' % (
|
|
ugettext(
|
|
'Page %(page_number)d'
|
|
) % {'page_number': document_page.page_number}
|
|
)
|
|
)
|
|
|
|
self.fields['contents'].initial = mark_safe(''.join(content))
|
|
|
|
contents = forms.CharField(
|
|
label=_('Contents'),
|
|
widget=TextAreaDiv(
|
|
attrs={
|
|
'class': 'text_area_div full-height',
|
|
'data-height-difference': 360
|
|
}
|
|
)
|
|
)
|
|
|
|
|
|
class DocumentPageContentForm(forms.Form):
|
|
contents = forms.CharField(
|
|
label=_('Contents'),
|
|
widget=TextAreaDiv(
|
|
attrs={
|
|
'class': 'text_area_div full-height',
|
|
'data-height-difference': 360
|
|
}
|
|
)
|
|
)
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
document_page = kwargs.pop('instance', None)
|
|
super(DocumentPageContentForm, self).__init__(*args, **kwargs)
|
|
content = ''
|
|
self.fields['contents'].initial = ''
|
|
|
|
try:
|
|
page_content = document_page.content_object.content.content
|
|
except DocumentVersionPageContent.DoesNotExist:
|
|
pass
|
|
else:
|
|
content = conditional_escape(force_text(page_content))
|
|
|
|
self.fields['contents'].initial = mark_safe(content)
|