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
49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
from __future__ import absolute_import, unicode_literals
|
|
|
|
from django.shortcuts import get_object_or_404
|
|
|
|
from rest_framework import generics
|
|
from rest_framework.response import Response
|
|
|
|
from mayan.apps.documents.models import Document
|
|
from mayan.apps.rest_api.permissions import MayanPermission
|
|
|
|
from .models import DocumentVersionPageContent
|
|
from .permissions import permission_content_view
|
|
from .serializers import DocumentPageContentSerializer
|
|
|
|
|
|
class APIDocumentPageContentView(generics.RetrieveAPIView):
|
|
"""
|
|
Returns the content of the selected document page.
|
|
"""
|
|
lookup_url_kwarg = 'page_pk'
|
|
mayan_object_permissions = {
|
|
'GET': (permission_content_view,),
|
|
}
|
|
permission_classes = (MayanPermission,)
|
|
serializer_class = DocumentPageContentSerializer
|
|
|
|
def get_document(self):
|
|
return get_object_or_404(klass=Document, pk=self.kwargs['document_pk'])
|
|
|
|
def get_document_version(self):
|
|
return get_object_or_404(
|
|
klass=self.get_document().versions.all(),
|
|
pk=self.kwargs['version_pk']
|
|
)
|
|
|
|
def get_queryset(self):
|
|
return self.get_document_version().pages.all()
|
|
|
|
def retrieve(self, request, *args, **kwargs):
|
|
instance = self.get_object()
|
|
|
|
try:
|
|
content = instance.content
|
|
except DocumentVersionPageContent.DoesNotExist:
|
|
content = DocumentVersionPageContent.objects.none()
|
|
|
|
serializer = self.get_serializer(content)
|
|
return Response(serializer.data)
|