Add support for new document page structure

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
This commit is contained in:
Roberto Rosario
2019-10-10 11:55:42 -04:00
parent 4a99a9df3e
commit 0699ad0556
87 changed files with 1973 additions and 707 deletions
@@ -3,10 +3,11 @@ from __future__ import absolute_import, unicode_literals
import logging
from django.contrib import messages
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext_lazy as _, ungettext
from mayan.apps.common.generics import (
ConfirmView, SingleObjectDetailView, SingleObjectListView
ConfirmView, MultipleObjectConfirmActionView, SingleObjectDetailView,
SingleObjectListView
)
from mayan.apps.common.mixins import ExternalObjectMixin
@@ -14,9 +15,10 @@ from ..events import event_document_view
from ..forms import DocumentVersionDownloadForm, DocumentVersionPreviewForm
from ..models import Document, DocumentVersion
from ..permissions import (
permission_document_download, permission_document_version_revert,
permission_document_version_view
permission_document_download, permission_document_tools,
permission_document_version_revert, permission_document_version_view
)
from ..tasks import task_update_page_count
from .document_views import DocumentDownloadFormView, DocumentDownloadView
@@ -142,6 +144,45 @@ class DocumentVersionRevertView(ExternalObjectMixin, ConfirmView):
)
class DocumentVersionUpdatePageCountView(MultipleObjectConfirmActionView):
model = DocumentVersion
object_permission = permission_document_tools
success_message = _(
'%(count)d document version queued for page count recalculation'
)
success_message_plural = _(
'%(count)d documents version queued for page count recalculation'
)
def get_extra_context(self):
queryset = self.object_list
result = {
'title': ungettext(
singular='Recalculate the page count of the selected document version?',
plural='Recalculate the page count of the selected document versions?',
number=queryset.count()
)
}
if queryset.count() == 1:
result.update(
{
'object': queryset.first(),
'title': _(
'Recalculate the page count of the document version: %s?'
) % queryset.first()
}
)
return result
def object_action(self, form, instance):
task_update_page_count.apply_async(
kwargs={'version_id': instance.pk}
)
class DocumentVersionView(SingleObjectDetailView):
form_class = DocumentVersionPreviewForm
model = DocumentVersion