Cleanup documents API code and names
This commit is contained in:
@@ -18,16 +18,16 @@ from permissions.models import Permission
|
|||||||
from .conf.settings import DISPLAY_SIZE, ZOOM_MAX_LEVEL, ZOOM_MIN_LEVEL
|
from .conf.settings import DISPLAY_SIZE, ZOOM_MAX_LEVEL, ZOOM_MIN_LEVEL
|
||||||
from .models import Document
|
from .models import Document
|
||||||
from .permissions import PERMISSION_DOCUMENT_VIEW
|
from .permissions import PERMISSION_DOCUMENT_VIEW
|
||||||
from .resources import DocumentResourceSimple
|
from .resources import ResourceDocument
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# API Views
|
# API Views
|
||||||
|
|
||||||
|
|
||||||
class APIReadOnlyInstanceModelView(RetrieveAPIView):
|
class APIDocumentView(RetrieveAPIView):
|
||||||
allowed_methods = ['GET']
|
allowed_methods = ['GET']
|
||||||
serializer_class = DocumentResourceSimple
|
serializer_class = ResourceDocument
|
||||||
queryset = Document.objects.all()
|
queryset = Document.objects.all()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from __future__ import absolute_import
|
|||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from .cleanup import cleanup
|
from .cleanup import cleanup
|
||||||
from .api import APIReadOnlyInstanceModelView, APIDocumentImageView
|
from .api import APIDocumentView, APIDocumentImageView
|
||||||
|
|
||||||
bootstrap_models = [
|
bootstrap_models = [
|
||||||
{
|
{
|
||||||
@@ -17,6 +17,6 @@ bootstrap_models = [
|
|||||||
cleanup_functions = [cleanup]
|
cleanup_functions = [cleanup]
|
||||||
|
|
||||||
version_0_api_services = [
|
version_0_api_services = [
|
||||||
{'urlpattern': url(r'^document/(?P<pk>[0-9]+)/$', APIReadOnlyInstanceModelView.as_view(), name='document-detail'), 'description': 'Show document data', 'url': 'document/<document ID>'},
|
{'urlpattern': url(r'^document/(?P<pk>[0-9]+)/$', APIDocumentView.as_view(), name='document-detail'), 'description': 'Show document data', 'url': 'document/<document ID>'},
|
||||||
{'urlpattern': url(r'^document/(?P<pk>[0-9]+)/image/$', APIDocumentImageView.as_view(), name='document-image'), 'description': 'Return a base64 image of the document', 'url': 'document/<document_id>/image/?page=<page number>&zoom=<zoom percent>&rotate=<rotation degrees>'},
|
{'urlpattern': url(r'^document/(?P<pk>[0-9]+)/image/$', APIDocumentImageView.as_view(), name='document-image'), 'description': 'Return a base64 image of the document', 'url': 'document/<document_id>/image/?page=<page number>&zoom=<zoom percent>&rotate=<rotation degrees>'},
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -7,39 +7,7 @@ from rest_framework import serializers
|
|||||||
from .models import Document
|
from .models import Document
|
||||||
|
|
||||||
|
|
||||||
class DocumentResourceSimple(serializers.HyperlinkedModelSerializer):
|
class ResourceDocument(serializers.HyperlinkedModelSerializer):
|
||||||
def versions(self, instance):
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
'version': version.get_formated_version(),
|
|
||||||
'major': version.major,
|
|
||||||
'minor': version.minor,
|
|
||||||
'micro': version.micro,
|
|
||||||
'release_level': version.release_level,
|
|
||||||
'serial': version.serial,
|
|
||||||
'timestamp': version.timestamp,
|
|
||||||
'comment': version.comment,
|
|
||||||
'mimetype': version.mimetype,
|
|
||||||
'encoding': version.encoding,
|
|
||||||
'filename': version.filename,
|
|
||||||
'checksum': version.checksum,
|
|
||||||
'download': reverse('document_version_download', args=[version.pk]),
|
|
||||||
'stored_filename': version.file.name,
|
|
||||||
# TODO: Add transformations
|
|
||||||
'pages': [
|
|
||||||
{
|
|
||||||
'content': page.content,
|
|
||||||
'page_label': page.page_label,
|
|
||||||
'page_number': page.page_number,
|
|
||||||
}
|
|
||||||
for page in version.pages.all()
|
|
||||||
]
|
|
||||||
|
|
||||||
}
|
|
||||||
for version in instance.versions.all()
|
|
||||||
]
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Document
|
model = Document
|
||||||
#fields = ('url', 'pk', 'document_type', 'uuid', 'date_added', 'description', 'expensive_methods', 'versions')
|
fields = ('url', 'document_type', 'uuid', 'date_added', 'description')
|
||||||
fields = ('url', 'document_type', 'uuid', 'date_added', 'description')#, 'versions')
|
|
||||||
|
|||||||
Reference in New Issue
Block a user