Switch to a resource and service based API from previous app based one.
Signed-off-by: Michael Price <loneviking72@gmail.com>
This commit is contained in:
committed by
Roberto Rosario
parent
f3427c7470
commit
b4bf9bfaee
@@ -1,9 +1,11 @@
|
||||
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 documents.models import DocumentPage
|
||||
from documents.models import Document, DocumentPage
|
||||
from rest_api.permissions import MayanPermission
|
||||
|
||||
from .models import DocumentPageContent
|
||||
@@ -14,20 +16,24 @@ from .serializers import DocumentPageContentSerializer
|
||||
class APIDocumentPageContentView(generics.RetrieveAPIView):
|
||||
"""
|
||||
Returns the content of the selected document page.
|
||||
---
|
||||
GET:
|
||||
parameters:
|
||||
- name: pk
|
||||
paramType: path
|
||||
type: number
|
||||
"""
|
||||
|
||||
lookup_url_kwarg = 'page_pk'
|
||||
mayan_object_permissions = {
|
||||
'GET': (permission_content_view,),
|
||||
}
|
||||
permission_classes = (MayanPermission,)
|
||||
serializer_class = DocumentPageContentSerializer
|
||||
queryset = DocumentPage.objects.all()
|
||||
|
||||
def get_document(self):
|
||||
return get_object_or_404(Document, pk=self.kwargs['document_pk'])
|
||||
|
||||
def get_document_version(self):
|
||||
return get_object_or_404(
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user