Files
mayan-edms/mayan/apps/rest_api/api_views.py
Michael Price 49bb7c879e Add root API showing the new endpoints.
Signed-off-by: Michael Price <loneviking72@gmail.com>
2018-04-01 20:00:38 -04:00

35 lines
1.0 KiB
Python

from __future__ import unicode_literals
from rest_framework import renderers
from rest_framework.authtoken.views import ObtainAuthToken
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.schemas.generators import EndpointEnumerator
from .classes import Endpoint
from .serializers import EndpointSerializer
class APIRoot(APIView):
def get(self, request, format=None):
"""
Return a list of all users.
"""
endpoint_enumerator = EndpointEnumerator()
endpoints = []
for url in sorted(set([entry[0].split('/')[2] for entry in endpoint_enumerator.get_api_endpoints()])):
if url:
endpoints.append(Endpoint(label=url))
serializer = EndpointSerializer(endpoints, many=True)
return Response(serializer.data)
class BrowseableObtainAuthToken(ObtainAuthToken):
"""
Obtain an API authentication token.
"""
renderer_classes = (renderers.BrowsableAPIRenderer, renderers.JSONRenderer)