Files
mayan-edms/mayan/apps/common/api_views.py
Roberto Rosario 7c4ae1aef0 Update common app API to viewsets
Update the API entries for content types and templates to use
viewsets and the new api_router_entries URL registraion
method.

Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
2019-01-19 01:04:59 -04:00

45 lines
1.2 KiB
Python

from __future__ import unicode_literals
from django.contrib.contenttypes.models import ContentType
from rest_framework import viewsets
from rest_framework.permissions import IsAuthenticated
from .classes import Template
from .serializers import ContentTypeSerializer, TemplateSerializer
class APIContentTypeViewSet(viewsets.ReadOnlyModelViewSet):
"""
list:
Return a list of all the available content types.
retrieve:
Return the given content type details.
"""
lookup_field = 'pk'
lookup_url_kwarg = 'content_type_id'
queryset = ContentType.objects.order_by('app_label', 'model')
serializer_class = ContentTypeSerializer
class APITemplateViewSet(viewsets.ReadOnlyModelViewSet):
"""
list:
Return a list of partial templates.
retrieve:
Return the given partial template details.
"""
lookup_url_kwarg = 'name'
permission_classes = (IsAuthenticated,)
serializer_class = TemplateSerializer
def get_object(self):
return Template.get(name=self.kwargs['name']).render(
request=self.request
)
def get_queryset(self):
return Template.all(rendered=True, request=self.request)