Update OCR app
Normalize API base names. Update ViewSet base class, model classes are not needed the OCR API views. Split API tests into content and submit tests. Puntuate view test strings. Make use of success and title strings. Make use of external object mixin in document type settings view. Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
+36
-36
@@ -7,7 +7,7 @@ from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
|
||||
from mayan.apps.documents.models import Document, DocumentVersion
|
||||
from mayan.apps.rest_api.viewsets import MayanAPIViewSet
|
||||
from mayan.apps.rest_api.viewsets import MayanAPIViewSet, MayanAPIGenericViewSet
|
||||
|
||||
from .permissions import permission_ocr_content_view, permission_ocr_document
|
||||
from .serializers import (
|
||||
@@ -26,7 +26,7 @@ class DocumentOCRAPIViewSet(MayanAPIViewSet):
|
||||
serializer_class = DocumentOCRSerializer
|
||||
|
||||
@action(
|
||||
detail=True, url_name='ocr-content', url_path='ocr'
|
||||
detail=True, url_name='content', url_path='ocr'
|
||||
)
|
||||
def ocr_content(self, request, *args, **kwargs):
|
||||
instance = self.get_object()
|
||||
@@ -37,7 +37,7 @@ class DocumentOCRAPIViewSet(MayanAPIViewSet):
|
||||
)
|
||||
|
||||
@action(
|
||||
detail=True, methods=('post',), url_name='ocr-submit',
|
||||
detail=True, methods=('post',), url_name='submit',
|
||||
url_path='ocr/submit'
|
||||
)
|
||||
def ocr_submit(self, request, *args, **kwargs):
|
||||
@@ -48,39 +48,7 @@ class DocumentOCRAPIViewSet(MayanAPIViewSet):
|
||||
)
|
||||
|
||||
|
||||
class DocumentVersionOCRAPIViewSet(MayanAPIViewSet):
|
||||
lookup_url_kwarg = 'document_version_id'
|
||||
object_permission_map = {
|
||||
'ocr_content': permission_ocr_content_view,
|
||||
'ocr_submit': permission_ocr_document,
|
||||
}
|
||||
queryset = DocumentVersion.objects.all()
|
||||
serializer_class = DocumentVersionOCRSerializer
|
||||
|
||||
@action(
|
||||
detail=True, url_name='ocr-content', url_path='ocr'
|
||||
)
|
||||
def ocr_content(self, request, *args, **kwargs):
|
||||
instance = self.get_object()
|
||||
serializer = self.get_serializer(instance)
|
||||
headers = self.get_success_headers(data=serializer.data)
|
||||
return Response(
|
||||
serializer.data, status=status.HTTP_200_OK, headers=headers
|
||||
)
|
||||
|
||||
@action(
|
||||
detail=True, methods=('post',), url_name='ocr-submit',
|
||||
url_path='ocr/submit'
|
||||
)
|
||||
def ocr_submit(self, request, *args, **kwargs):
|
||||
instance = self.get_object()
|
||||
instance.submit_for_ocr(_user=request.user)
|
||||
return Response(
|
||||
data=None, status=status.HTTP_202_ACCEPTED
|
||||
)
|
||||
|
||||
|
||||
class DocumentPageOCRAPIViewSet(MayanAPIViewSet):
|
||||
class DocumentPageOCRAPIViewSet(MayanAPIGenericViewSet):
|
||||
lookup_url_kwarg = 'document_page_id'
|
||||
object_permission_map = {
|
||||
'ocr_content': permission_ocr_content_view,
|
||||
@@ -103,3 +71,35 @@ class DocumentPageOCRAPIViewSet(MayanAPIViewSet):
|
||||
return Response(
|
||||
serializer.data, status=status.HTTP_200_OK, headers=headers
|
||||
)
|
||||
|
||||
|
||||
class DocumentVersionOCRAPIViewSet(MayanAPIViewSet):
|
||||
lookup_url_kwarg = 'document_version_id'
|
||||
object_permission_map = {
|
||||
'ocr_content': permission_ocr_content_view,
|
||||
'ocr_submit': permission_ocr_document,
|
||||
}
|
||||
queryset = DocumentVersion.objects.all()
|
||||
serializer_class = DocumentVersionOCRSerializer
|
||||
|
||||
@action(
|
||||
detail=True, url_name='content', url_path='ocr'
|
||||
)
|
||||
def ocr_content(self, request, *args, **kwargs):
|
||||
instance = self.get_object()
|
||||
serializer = self.get_serializer(instance)
|
||||
headers = self.get_success_headers(data=serializer.data)
|
||||
return Response(
|
||||
serializer.data, status=status.HTTP_200_OK, headers=headers
|
||||
)
|
||||
|
||||
@action(
|
||||
detail=True, methods=('post',), url_name='submit',
|
||||
url_path='ocr/submit'
|
||||
)
|
||||
def ocr_submit(self, request, *args, **kwargs):
|
||||
instance = self.get_object()
|
||||
instance.submit_for_ocr(_user=request.user)
|
||||
return Response(
|
||||
data=None, status=status.HTTP_202_ACCEPTED
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user