Source code for intranet.apps.bus.api
from rest_framework import generics
from ..auth.rest_permissions import ApiAndOauthPermission
from .models import Route
from .serializers import RouteSerializer
[docs]class RouteList(generics.ListAPIView):
"""API endpoint that retrieves information about buses.
/api/bus: retrieve a list of all buses\n
/api/bus/num: retrieve information about bus number num
"""
serializer_class = RouteSerializer
permission_classes = (ApiAndOauthPermission,)
[docs] def get_queryset(self):
return Route.objects.all()
[docs]class RouteDetail(generics.RetrieveAPIView):
"""API endpoint that retrieves information about a specific bus route.
/api/bus/<num>: retrieve information about bus number <num>
"""
serializer_class = RouteSerializer
permission_classes = (ApiAndOauthPermission,)
# override get_queryset instead of using queryset=...
# so that it always returns fresh data
[docs] def get_queryset(self):
return Route.objects.all()